how to get the job id from qsub
Asked Answered
L

2

9

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')

Lexicon answered 6/4, 2014 at 11:56 Comment(1)
I believe there are serveral different batch systems that use a command called qsub. I've add the "pbs" tag to indicate which one you're asking about.Calculation
I
7

qsub has a very predictable output. Many automated submission systems (such as Grid interfaces) simply parse the output from qsub, looking for the jobid.

An example of parsing is available from the BLAHP project (European grid middleware).

jobID=`${pbs_binpath}/qsub $bls_tmp_file` # actual submission
...

# The job id is actually the first numbers in the string (slurm support)
jobID=`echo $jobID | awk 'match($0,/[0-9]+/){print substr($0, RSTART, RLENGTH)}'`

(source)

This code has been used in production for many years, and has worked for qsub in both PBS, PBS Pro, and SLURM.

Impotent answered 7/4, 2014 at 0:36 Comment(0)
S
11

You can use the -terse:

$ echo sleep 5 | qsub -terse
3543
Septi answered 30/11, 2016 at 12:32 Comment(0)
I
7

qsub has a very predictable output. Many automated submission systems (such as Grid interfaces) simply parse the output from qsub, looking for the jobid.

An example of parsing is available from the BLAHP project (European grid middleware).

jobID=`${pbs_binpath}/qsub $bls_tmp_file` # actual submission
...

# The job id is actually the first numbers in the string (slurm support)
jobID=`echo $jobID | awk 'match($0,/[0-9]+/){print substr($0, RSTART, RLENGTH)}'`

(source)

This code has been used in production for many years, and has worked for qsub in both PBS, PBS Pro, and SLURM.

Impotent answered 7/4, 2014 at 0:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.