0

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.

alper
  • 2,919
  • 9
  • 53
  • 102
  • I couldn't comment on how robust your strategy is. In this case though you could `grep` the output of `sacct` once more the name of your job. – Tom de Geus Sep 11 '18 at 06:27
  • 1
    If you want to do this often you could consider storing the job-id to a file from the job-script, by for example `echo "$SLURM_JOB_ID" > jobid.log` – Tom de Geus Sep 11 '18 at 06:30

1 Answers1

3

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.

damienfrancois
  • 52,978
  • 9
  • 96
  • 110