Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the job id from qsub

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

like image 745
sflee Avatar asked Apr 06 '14 11:04

sflee


People also ask

How qsub works?

The qsub command will submit the script to the server defined by the destination argument. If the destination is a routing queue, the job may be routed by the server to a new destination. If the -q option is not specified, the qsub command will submit the script to the default server.

What is qsub command?

The qsub command is used to submit jobs to the queue. job, as previously mentioned, is a program or task that may be assigned to run on a cluster system. qsub command is itself simple, however, it to actually run your desired program may be a bit tricky. is because qsub, when used as designed, will only run scripts.

How do I submit a PBS job?

Job submission is accomplished using the qsub command, which takes a number of command line arguments and integrates such into the specified PBS command file. The PBS command file may be specified as a filename on the qsub command line or may be entered via STDIN. The PBS command file does not need to be executable.

What is Pbs_o_workdir?

PBS_O_WORKDIR the absolute path of the current working directory of the qsub command.


2 Answers

You can use the -terse:

$ echo sleep 5 | qsub -terse
3543
like image 70
Martin M. Avatar answered Oct 05 '22 14:10

Martin M.


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.

like image 36
Derek Avatar answered Oct 05 '22 14:10

Derek