Qsub multiple jobs in linux shell bash

Hi everyone,

I'm new here. I'll try to introduce my issue.
I'm trying to run multiple jobs on my PC cluster which works with linux shell (bash).
I usually submit one single job at time. Now, I'm struggling so much to make the submission automatic.
I have the project files stored in nested folders. I have successfully created the directories and imported the files correctly in each folder, but the jobs still don't run. I report the error files I get:

*> [compute-0-2.local:15366] Warning: could not find environment variable "LSTC_LICENSE_SERVER"*
*> [compute-0-2.local:15366] Warning: could not find environment variable "LSTC_LICENSE"*
*> /var/spool/torque/mom_priv/jobs/16308.archimede.pcmgroup.dmti.unifi.it.SC: line 35: l2a_r712: command not found*

I share here my script. Any help will be very appreciated.

#!/bin/bash

NUMBERS=$(seq 3 3)

for NUM in ${NUMBERS}
do

	NAME=run__0000${NUM}
	echo "Submitting: ${NAME}"
	
	PSB="#!/bin/bash\n\
	#PBS -N ${NAME}\n\
	#PBS -l nodes=compute-0-2:ppn=8\n\
	#PBS -l walltime=50:00:00\n\
	#PBS -r n\n\
	
	cd \$PBS_O_WORKDIR\n\
	. /opt/torque/etc/openmpi-setup.sh\  # set the enviroment vars needed to make OpenMPI work with torque
	"
	
	MODEL=tensile_test_results
	APPROACH=basic_1/${NAME}/m_1
	WORKDIR=/scratch/$USER/$APPROACH
	RESULTS=$HOME/Analisi/$APPROACH
	
	NODI=$(awk '!x[$0]++' $PBS_NODEFILE)  		# reads compute nodes and eliminates duplicates
	rocks run host $NODI "mkdir -p $WORKDIR"    # crea sul cluster le directory che ho nella $HOME

	# stage in
	cp $RESULTS/* $WORKDIR						# copia i file in $RESULTS nella $WORKDIR

	# run
	cd $WORKDIR
	/usr/lib64/openmpi/bin/mpirun -x LSTC_LICENSE_SERVER -x LSTC_LICENSE -np 8 mpp971s_r712 MEMORY=800000000 MEMORY2=80000000 i=$MODEL.k
	l2a_r712 binout**

		# stage out
	cp -p $WORKDIR/runrsf* $RESULTS
	cp -p $WORKDIR/d3dump* $RESULTS
	cp -p $WORKDIR/nodout $RESULTS
	cp -p $WORKDIR/glstat $RESULTS
	cp -p $WORKDIR/sbtout $RESULTS
	cp -p $WORKDIR/matsum $RESULTS
	cp -p $WORKDIR/deforc $RESULTS
	cp -p $WORKDIR/abstat $RESULTS
	cp -p $WORKDIR/elout $RESULTS
	cp -p $WORKDIR/jntforc $RESULTS
	cp -p $WORKDIR/rwforc $RESULTS
	cp -p $WORKDIR/rcforc $RESULTS
	cp -p $WORKDIR/sbtout $RESULTS
	cp -p $WORKDIR/secforc $RESULTS
	cp -p $WORKDIR/spc* $RESULTS
	cp -p $WORKDIR/sleout $RESULTS
	cp -p $WORKDIR/d3p* $RESULTS
	cp -p $WORKDIR/d3hsp $RESULTS
	rocks run host $NODI "cp -p $WORKDIR/binout* $RESULTS"
	rocks run host $NODI "cp -p $WORKDIR/mes* $RESULTS"
	
	echo -e ${PSB} | qsub
	

done

Many thanks

Well it looks like you know what you are doing. For me it is more difficult because I don't know :grinning:.
But I think lines 35 and 35 should be one line, but it is broken by an unintended newline. That causes l2a_r712: command not found. Could that be correct?
And then you are missing environment variables. I guess they come from "openmpi-setup.sh". You source that file in the $PSB variable, but not in the script itself. Perhaps you should source that file once more?

Maybe you should consider just following the messages in the error log?

First, insure your environmental variables are working properly. Then see what errors you get.

*> [compute-0-2.local:15366] Warning: could not find environment variable "LSTC_LICENSE_SERVER"*
*> [compute-0-2.local:15366] Warning: could not find environment variable "LSTC_LICENSE"*

Maybe just this?

/usr/lib64/openmpi/bin/mpirun -x  $LSTC_LICENSE_SERVER -x $LSTC_LICENSE - ...

missing $ for the env variables... and they are maybe required to access the unfound command?