1

I am running a bash script to submit multiple jobs. The submission of a job only happens if such job is not already running. I want to use an if statement inside my bash script to simply check if "job123" is already running or in the queue.

I have tried different options with qstat and qstatus but I can't seem to check by job name. How can this information be retrieved? Also these outputs are just strings, I also did not have any luck using grep but I think there must be a specific command.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Herman Toothrot
  • 353
  • 1
  • 3
  • 12

2 Answers2

1

I have been able to solve with

qstat -r | grep -cw "jobname"

which gives a 0 or 1 which then I can use inside an if statement. It seems to me more of a hack than anything. The -r it's important because it displays full names of jobs.

Herman Toothrot
  • 353
  • 1
  • 3
  • 12
1

Sun/Oracle Grid Engine's qstat utility only allows you to filter your jobs by user and job ID. If you need to filter by job name, you will have to grep for it:

qstat -u $USER | grep -w jobname

For use in an if-statement:

if qstat -u $USER | grep -q -w "$jobname"; then
  # job is in the queue
else
  # job is not in the queue
fi

After a brief search on the web, I also found that some versions of qstat appears to be able to filter by job name using the -j switch:

qstat -u $USER -j "$jobname"

I haven't been able to verify if this works or not. Other versions of this utility clearly can't do this (and doesn't even support -u).

Kusalananda
  • 320,670
  • 36
  • 633
  • 936