-1

我的 bash 脚本将比较并从不同的两个文件中读取两个值。如果它们不相等,则脚本应取消 slurm 上的作业。我想我应该得到工作ID。但我不知道如何获取作业 ID 并在 bash 脚本中取消它。我怎样才能做到这一点?

#!/bin/bash

#read the the first line (lets suppose a) from file1.txt
#read the the third line (lets suppose b) from file2.txt      
if  (a != b); then  
  # get the job-ID
  # cancel the job
 fi
4

2 回答 2

0

这可能取决于本地环境设置。在我的情况下,当我向调度程序提交作业时,以下字符串将输出到 stdout

Submitted batch job 1413273

您可以捕获此字符串并提取 ID 号,然后您可以使用它来取消相关作业

id=$(sbatch run.qscript | awk '{print $4}')
if [ $a -ne $b ]; then
    scancel $id
fi

请注意,这里的比较符号假定ab是整数。如果它们是字符串,您应该使用

if [ "$a" != "$b" ]; then
于 2015-03-15T17:44:46.343 回答
0

SLURM_JOB_ID可以在提交脚本中从环境变量中检索 slurm 作业 ID 。所以你需要写:

scancel $SLURM_JOB_ID
于 2017-08-26T17:29:49.273 回答