Depending on the queue system installed on the cluster, you might have the command
qwait at your disposal. If not, you can actually use the qstat command as suggested by catkin. First store the Job ID (standard output of the qsub command) in a variable, then use the Job Id as argument to qstat. Usually the exit status is 0 for running or queued jobs, 1 otherwise (the man page of qsub should confirm).
Something (simple) like this should do the trick:
Code:
jobid=$(qsub job1.sh)
while qstat $jobid > /dev/null 2>&1
do
sleep 300
done
I usually redirect standard output to /dev/null (to avoid the job summary list) together with standard error (to avoid the error message coming out when the job has finished and qstat does not find it anymore). If you want to log anything from you script, better to redirect (append) them to a log file.
Hope this helps.