35

I submitted lots of SLURM job script with debug time limit (I forgot to change the time for actual run). Now they are all submitted at the same time, so they all start with job ID 197xxxxx. Now, I can do

squeue -u $USER | grep 197 | awk '{print $1}' 

to print the job ID's I want to delete. But how do I use scancel command on all these ID's. The output from the above shell command would look like

19726664
19726663
19726662
19726661
19726660
19726659
19726658
19726657
19726656
19726655
19726654
19726653
19726652
19726651
19726650

6 Answers 6

38
squeue -u $USER | grep ^197 | awk '{print $1}' | xargs -n 1 scancel

Check the documentation for xargs for details. If scancel accepts multiple job ids (it should), you may omit the -n 1 part.

0
19

In order to cancel all my slurm jobs (omitting the OP's grep 197), I found I had to prune the fist line of the squeue output, which contained column titles, also:

squeue -u $USER | awk '{print $1}' | tail -n+2 | xargs scancel
2
  • This works for me
    – Tack_Tau
    Commented Dec 24, 2021 at 22:05
  • Since you're using awk anyway, just have it skip the first line instead: ... | awk 'NR > 1 {print $1}' | xargs scancel
    – muru
    Commented Jan 31 at 6:34
18

This is what i generally use:

  1. cancel all my jobs:

    scancel -u <my_user_name>
    
  2. cancel by filtering: i.e. cancel all jobs having a jobId that starts by 26699):

    squeue --format="%.18i" --me -h | grep -w 26699.* | xargs scancel
    
11

A bit shorter version with only the job numbers printed by squeue:

squeue --me -h -o "%i" | xargs scancel
2

Since this is a simplified solution, you can also do this:

squeue -u $USER -h | awk '{print $1}' | xargs scancel

This omits the formatting options and instead removes the header with the -h flag.

1

All you need if you want to cancel all jobs is: scancel --me!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .