Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Say you dispatch thousands of jobs with Slurm, but goofed something up and want to cancel some of those jobs. Here is a bash script to do that. I stole the script from somebody named "cas" on stack exchange. NOTE: if

  • If you want to cancel all of your jobs then you can use scancel -u username, where

...

  • username

...

  • is your system username (i.e. jharri62 is my username).

...

  • Often you may want to be selective and keep some jobs running, but cancel others. This situation can be handled via the script below (source: somebody named cas on stack exchange).

For more see: https://www.rc.fas.harvard.edu/resources/documentation/convenient-slurm-commands/

Step-by-step guide

  1. Make a file to house the program. Put it somewhere convenient, like in your home directory, or in a directory of common scripts in your home directory. One way to make a file is

    "touch

    nano yourfilename

    "

    .sh

  2. Open the file with nano or another editor and paste the following into it:

    Code Block
    languagebash
    #!/bin/bash
    
    
    declare -a jobs=()
    
    if [ -z "$1" ] ; then

     echo "Minimum Job Number argument is required. Run as '$0 jobnum'"

     exit
    1
     fi
    
    minjobnum="$1"
    
    myself="$(id -u -n)"
    
    for j in $(squeue --user="$myself" --noheader --format=%i)
    ; do
    if [
     ; doif [ "$j" -gt "$minjobnum" ] ;
    then
    jobs
     thenjobs+=($j)

    fi
    donescancel
    fidone
    scancel "${jobs[@]}"
  3. Make the file executable

    with

    : chmod

    "chmod

    u+x

    yourfile"

    yourfilename.sh

  4. Usage is:

    "bash yourfile 300000"

    yourfilename.sh 300000 where 300000 is the base job id number used to delimit where wanted jobs stop. In other words, any of your jobs with an ID smaller than this number will be retained, but jobs with IDs larger than this number will be removed. This will not mess with anybody else's jobs.

...

Filter by label (Content by label)
showLabelsfalse
max5
spacescom.atlassian.confluence.content.render.xhtml.model.resource.identifiers.SpaceResourceIdentifier@10994
showSpacefalse
sortmodified
reversetrue
typepage
cqllabel = "teton" and type = "page" and space = "DSC"
labelsteton

...

hiddentrue

...

  1. Alternatively, if the current directory is not in your PATH, use: bash yourfilename.sh 300000