3

This may be a very simple question, but if I have the job ID, how would I get the state of the job submitted through SGE? I basically want to check on a job ID and see if it's in an error state, it's still running, or it's completed.

I was thinking of something like this

qstat -u '*' | grep 123456

But if the job ID is low, it may return lines other than the one that I want. And using a command like this...

qstat -j '123456'

...doesn't seem to return the job state.

Greg B
  • 609
  • 6
  • 19

3 Answers3

1

Issue the command:

qstat -xml

The results will be in XML format. You can parse the result and extract the state:

<job_list state="pending">
  <JB_job_number>3150728</JB_job_number>
  <JAT_prio>0.00000</JAT_prio>
  <JB_name>snpReference</JB_name>
  <JB_owner>me</JB_owner>
  <state>hqw</state>
  <JB_submission_time>2016-11-23T11:54:01</JB_submission_time>
  <queue_name></queue_name>
  <jclass_name></jclass_name>
  <slots>1</slots>
</job_list>
Steve
  • 1,250
  • 11
  • 25
0

I have migrated to Torque/Maui so solution may not be exact for GridEngine.

For using qstat and grep try word-based search:

qstat -u '*' | grep -w 123456

Or, use awk

qstat -u '*' | awk '$1 == 123456 { print }'

For Toque/Maui I can get the job state using qstat -f $jobid:

qstat -f 123456 | grep job_state

Maybe you can do similar with the -j option:

qstat -j $job_id | grep job_state
Vince
  • 3,325
  • 2
  • 23
  • 41
  • The -f option doesn't seem to work. It gives an error that the jobID is an invalid option. It works fine as `qstat -j` though. I'm using SGE 8.1.8 – Greg B Nov 02 '16 at 12:52
  • Indeed. I changed this back to use the `-j` option. – Vince Nov 02 '16 at 13:02
  • Seems for my version of qstat, it doesn't return the `job_state` value when using the `-j` option. – Greg B Nov 02 '16 at 15:07
  • Can you post example output please. Also, you can change output format using different flags. See OUTPUT FORMATS section of http://gridscheduler.sourceforge.net/htmlman/htmlman1/qstat.html. – Vince Nov 02 '16 at 15:35
0

Just make your regex more specific:

qstat | grep "^123456\s"

That way you'll only get jobs whose whole job number is the one you specify.

leekaiinthesky
  • 5,413
  • 4
  • 28
  • 39