允许TORQUE中的qsub等待作业完成的Bash脚本,非常类似于SGE系统中的-sync y

我正在使用带有Torque / Maui系统的集群.我有一个使用qsub命令提交一个作业的bash脚本,然后做了几件事,比如移动文件,写ASCII文件,并检查我提交的作业的输出.关于此输出,基本上,如果它包含数字1,则需要再次提交作业.如果不同于1,则bash脚本会执行其他操作.

问题是qsub在后台运行,并且所有bash都会立即进行评估.我想强迫qsub表现得非常像awk,cat,sort等…当脚本在这些命令完成后进一步发展 – 如果没有放在后台.

所以,我需要在第一个qsub上停止bash,并在qsub完成后继续运行,这意味着,当作业完成时.有没有办法做到这一点?它将类似于:

-sync y    # in the SGE system,for instance.

是)我有的:

#!/bin/bash
.
.
some commands
.
.
qsub my_application  # need to wait until my_application get done
.
.
more commands
.
.
my_application_output=(`cat my_application_output.txt`)

case "$my_application_output" in
["1"])
     qsub my_application
     ;;
["0"])
     some commands
     ;;
["100"])
     some commands
     ;;
*)
     some commands
     exit 1

esac

.
.

一些言论

>使用时不方便:qsub -I -x,一旦我想将输出保留在输出文件中;并且不希望通过启动交互模式锁定节点(-I)
>我想这不是一个简单的工作依赖问题,一旦重新提交1)可能发生,2)不能,而且,最重要的是,如果发生(1),它可能是几次.

谢谢大家

10月3日凌晨4点05分:“这不是一个简单的工作依赖问题”

您必须创建一个简单的作业依赖性问题 – 无论如何都足以让脚本处理.事实上,你的脚本在my_application_output.txt上进行了操作,那为什么不睡觉呢?就像是

#!/usr/bin/env bash
# I prefer to have constants at the top
my_application_output_fp='/path/to/my_application_output.txt' 
#
#
# some commands
#
#
qsub my_application
#
#
# more commands
#
#

# sleep until my_application outputs
while [[ ! -r "${my_application_output_fp}" ]] ; do
    sleep 1
done

my_application_output="$(cat ${my_application_output_fp})"
# process it

如果my_application_output.txt在my_application结束之前写得太长,请在my_application退出之前更改my_application以写入一个标志文件,并在其上执行以下操作:

#!/usr/bin/env bash
my_application_flag_fp='/path/to/my_application_flag.txt' 
my_application_output_fp='/path/to/my_application_output.txt' 
#
#
# some commands
#
#
qsub my_application
#
#
# more commands
#
#

# sleep until my_application writes flag
while [[ ! -r "${my_application_flag_fp}" ]] ; do
    sleep 1
done

if [[ ! -r "${my_application_output_fp}" ]] ; then
    # handle error
fi
# else
my_application_output="$(cat ${my_application_output_fp})"
# process it

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...