3

On the system I'm using I often need to cancel jobs I run. I can check my jobs like this:

$ showq|grep jquick
2001744              jquick    Running   120    00:08:26  Mon Apr 11 11:06:02
2002020              jquick    Running   120    00:22:04  Mon Apr 11 11:19:40
2003328              jquick    Running   240     1:43:34  Mon Apr 11 12:41:10
2006300              jquick    Running   120     4:59:16  Mon Apr 11 15:56:52
2006312              jquick    Running   120     4:59:16  Mon Apr 11 15:56:52

What I do now is cancel each job ID manually: $ canceljob 2001744 2002020 2003328 2006300 2006312.

How can I filter this output to directly pipe the job IDs to canceljob?

2
  • 2
    Does qselect -u jquick give you output that's easier to use? Apr 12, 2016 at 17:27
  • Yes. Thanks - I didn't know I could do that.
    – kilojoules
    Apr 12, 2016 at 18:06

2 Answers 2

3

try

showq | awk '/jquick/ { printf "canceljob %d\n",$1}'

if OK, pipe to bash, or

 showq | awk '/jquick/ { print $1}' | xargs canceljob
3

Parsing whitespace-delimited columns is something awk does well.

canceljob $(showq | awk '$2 == "jquick" {print $1}')

or more directly

showq | awk '$2 == "jquick" {system("canceljob " + $1)}'

Alternatively, pass a constraint to showq to make it report only the desired jobs.

canceljob $(showq -w user=jquick)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .