Shell – Best way to cancel all the SLURM jobs from shell command output

shellslurm

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

Best Answer

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.

Related Question