Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

delete jobs by grepping qstat output and sending jobid to qdel?

Tags:

grep

bash

pbs

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 [email protected]            1        
 326594 0.50500 run        user         r     01/06/2011 11:13:34 [email protected]            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.

like image 419
David LeBauer Avatar asked Jan 03 '11 22:01

David LeBauer


1 Answers

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.

like image 120
SiegeX Avatar answered Oct 19 '22 19:10

SiegeX