Search code examples
slurmsacct

Slurm: How to obtain only jobID using jobName through a script


If I know the name of a job I have run, how could I return only its jobID through a script.

For example, running sacct --name run.sh returns following output, where I want to return only 50 (jobID).

$ sacct --name run.sh
       JobID    JobName  Partition    Account  AllocCPUS      State ExitCode
------------ ---------- ---------- ---------- ---------- ---------- --------
50               run.sh      debug      alper          1  COMPLETED      0:0
50.batch          batch                 alper          1  COMPLETED      0:0

As a solution I can run: sacct --name run.sh | head -n3 | tail -n1 | awk '{print $1}' that returns 50, but sometimes order of 50 and 50.batch changes for the other jobs.


Solution

  • Use the following combination of options:

    sacct -n -X --format jobid --name run.sh 
    

    where

    • -n will suppress the header
    • -X will suppress the .batch part
    • --format jobid will only show the jobid column

    This will output only the jobid, but if several jobs correspond to the given job name, you will get several results.