如何在shell脚本中完成Grid Engine的qsub作业后执行命令?

时间:2016-11-29 07:38:58

标签: shell qsub

我现在正在编写一个shell脚本,包括在工作节点中并行的一些qsub作业,然后汇总摘要统计信息并写入文件“temperature.txt”。但是,本地命令将在qsub将作业到达节点后立即执行。是否有“wait [pid]”可以应用于qsub作业ID?

我的代码如下所示:

echo "Burning..."
var=0
while [ $var -ne 1 ]
do
    qsub -hold_jid update -t 1-$1:1 -N mcmc_bn_$T -S /bin/sh -j y -cwd ./bn_mcmc.sh # Submit mcmc
    qsub -hold_jid mcmc_bn_$T  -N update update.sh $1
    T=$(tail -n 1 ./temp/temperature.txt)
    echo $T
    var=$(awk 'BEGIN{ print "'$T'"<1}') # when $T<1 => $var=1
    echo $var
done

提前致谢!

1 个答案:

答案 0 :(得分:0)

感谢所有参与讨论的人。

我通过以下脚本找到了解决方案:http://ccn.ucla.edu/wiki/index.php/How_to_have_a_script_wait_for_jobs_before_proceeding

基本他/她写了一个脚本调用jobhold.sh来检查qstat每30秒(可以指定)。代码很简单如下:

#!/bin/bash
# jobhold.sh
# JB 8/2010
# usage: 
#       jobhold.sh qsub <my_command>
#       jobhold.sh q.sh <my_command>
# For commands that are submitted to cluster, hold until jobs have completed
shopt -s expand_aliases
sleep_time=30 # seconds; don't make this too short! don't want to tax system with excessive qstat calls
me=`whoami`
alias myqstat='qstat | grep $me'
stdout=`$@` # call the command and capture the stdout
id=`echo $stdout | awk -F' ' '{print $3}'` # get the jobid
status=`myqstat | grep $id` # check to see if job is running
while [ -n "$status" ] # while $status is not empty
do
    sleep $sleep_time
status=`myqstat | grep $id`
done

通过将此脚本放在接下来的命令之前,它们将在完成所有qsub个作业后运行。如果您有其他想法或更有效的方法来解决这个问题,请继续发帖。谢谢!

最佳,