如何通过bash或qsub调用PBS脚本

时间:2014-06-02 04:46:36

标签: bash pbs

我有一个处理多个环境变量的PBS脚本。 PBS是bash的包装器,它将bash脚本发送到作业调度队列。处理过的变量形成一个运行scientific application的命令。 PBS脚本是用bash编写的,其中包含bash注释中编码的作业调度程序的附加信息。

如何以编程方式确定我的脚本是否由qsub调用,解释PBS脚本的命令,或者是否由bash调用?

如果脚本在bash下运行,我想将该调用视为空运行,并且只打印出生成的命令。这样就完全绕过了作业队列。

2 个答案:

答案 0 :(得分:3)

这可能不是完全可靠的,但可能有效的一种启发式方法是测试下列任何环境变量的存在,这些变量往往在qsub下定义,如列出here。 / p>

PBS_O_HOST (the name of the host upon which the qsub command is running)
PBS_SERVER (the hostname of the pbs_server which qsub submits the job to)
PBS_O_QUEUE (the name of the original queue to which the job was submitted)
PBS_O_WORKDIR (the absolute path of the current working directory of the qsub command)
PBS_ARRAYID (each member of a job array is assigned a unique identifier)
PBS_ENVIRONMENT (set to PBS_BATCH to indicate the job is a batch job, or to PBS_INTERACTIVE to indicate the job is a PBS interactive job)
PBS_JOBID (the job identifier assigned to the job by the batch system)
PBS_JOBNAME (the job name supplied by the user)
PBS_NODEFILE (the name of the file contain the list of nodes assigned to the job)
PBS_QUEUE (the name of the queue from which the job was executed from)
PBS_WALLTIME (the walltime requested by the user or default walltime allotted by the scheduler)

答案 1 :(得分:1)

您可以查看bash的父来电者:

CALLER=$(ps -p "$PPID" -o comm=)
if [[ <compare $CALLER with expected process name> ]]; then
    <script was called by qsub or something>
fi

额外注意:Bash始终有一个未导出的变量集:$BASH_VERSION因此,如果设置了它,您确定该脚本与Bash一起运行。剩下的问题只是关于哪一个叫它。

另外,不要在子shell ()内运行检查,因为您可能会从$PPID获取相同shell的进程,而不是调用者。

如果您的脚本调用的级别更深,$PPID不够,您可以使用ps -p <pid> -o ppid=递归扫描父pid。