11

I am using PBS job scheduler on my cluster, and I would like to delete jobs older than a certain date using qdel; alternatively it would be sufficient to be able to sort the results of qstat by date.

qstat gives this output:

job-ID  prior   name       user         state submit/start at     queue                          slots ja-task-ID 
-----------------------------------------------------------------------------------------------------------------
 326539 0.50500 run        user         r     01/06/2011 11:13:34 all.q@compute-0-0.local            1        
 326594 0.50500 run        user         r     01/06/2011 11:13:34 all.q@compute-0-0.local            1    

and I can delete jobs with qdel:

qdel 326539

and the jobs I want to delete can be located using grep:

qstat > foo; grep 01/06 foo

my current work around is to paste the output from above into a spreadsheet, sort by job-ID, and then qdel {min..max},

Can I combine these steps into a single command?

Assistance appreciated.

David LeBauer
  • 31,011
  • 31
  • 115
  • 189

1 Answers1

10

awk

qstat | awk '$6 ~ "01/06" {cmd="qdel " $1; system(cmd); close(cmd)}'

Bash

#!/bin/bash

match="01/06"

while read job; do
  set -- $job
  if [[ $6 =~ $match ]]; then
    qdel "$1"
  fi
done < <(qstat)

If you want to do a dry-run, then change qdel "$1" to echo qdel "$1" to see what it would have done.

SiegeX
  • 135,741
  • 24
  • 144
  • 154