bash 通过 grepping qstat 输出并将 jobid 发送到 qdel 来删除作业?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4588961/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
delete jobs by grepping qstat output and sending jobid to qdel?
提问by David LeBauer
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 qstatby date.
我在我的集群上使用 PBS 作业调度程序,我想使用qdel;删除早于某个日期的作业;或者,能够qstat按日期对结果进行排序就足够了。
qstatgives this output:
qstat给出这个输出:
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:
qdel 326539
and the jobs I want to delete can be located using grep:
可以使用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},
我目前的工作是将上面的输出粘贴到电子表格中,按作业 ID 排序,然后qdel {min..max},
Can I combine these steps into a single command?
我可以将这些步骤合并为一个命令吗?
Assistance appreciated.
帮助表示赞赏。
采纳答案by SiegeX
awk
awk
qstat | awk ' ~ "01/06" {cmd="qdel " ; system(cmd); close(cmd)}'
Bash
重击
#!/bin/bash
match="01/06"
while read job; do
set -- $job
if [[ =~ $match ]]; then
qdel ""
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.
如果您想进行试运行,请更改qdel "$1"为echo qdel "$1"以查看它会做什么。

