42

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

41
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.

1
  • 1
    As an alternative to grepping specific prefixes, one can simply skip the header line in the output of awk: shell squeue -u $USER | awk 'NR>1 {print $1}' | xargs scancel Commented Jul 17, 2024 at 6:20
29

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 
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 Commented Dec 24, 2021 at 22:05
  • 1
    Since you're using awk anyway, just have it skip the first line instead: ... | awk 'NR > 1 {print $1}' | xargs scancel Commented Jan 31, 2024 at 6:34
11

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

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

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

1
  • This solution is so much easier than some of the other answers. Commented Jul 10 at 16:58
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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.