how to get the job id from qsub

sflee picture sflee · Apr 6, 2014 · Viewed 7.5k times · Source

I am using a cluster. I will use qsub command to distribute my job, what I want is I can get back the job id so that I can monitor the job.

Basically, I want some thing like this:

#!/bin/bash
JOBID=$( qsub job1 )
# Monitoring base on $JOBID

I found a page http://wiki.ibest.uidaho.edu/index.php/Tutorial:_Submitting_a_job_using_qsub, and it talks about a variable PBS_JOBID but I don't know how to use it. Does anyone know how to do it?

(My solution now is jobID='qsub task | cut -d ' ' -f 3')

Answer

Martin M. picture Martin M. · Nov 30, 2016

You can use the -terse:

$ echo sleep 5 | qsub -terse
3543