获取作业ID并将其放入bash命令 [英] Get Job id and put them into a bash command

查看:58
本文介绍了获取作业ID并将其放入bash命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我只需要在所有以前的运行完成后才执行bash文件,所以我可以使用:

Hello for a projet I need to execute a bash file only when all previous run have been finished so I use :

sbatch -d afterok:$JobID1:$JobID2:$JobIDN final.sh 

为了运行我执行的JobIDN

in Order to run the JobIDN I do

for job in Job*.sh ; do sbatch $job; done 

然后打印所有jobIDs

我只是想知道是否有人拥有一个命令以获取这些ID并将它们直接放入命令中:

I just wondered if someone haave a command in order to grab these IDs and put them directly to the command :

sbatch -d afterok:$JobID1:$JobID2:$JobIDN final.sh 

例如

for job in Job*.sh ; do sbatch $job; done 
1
2
3


sbatch -d afterok:$1:$2:$3 final.sh 

推荐答案

您可以使用

for job in Job*.sh ; do sbatch --parsable $job; done | paste -s -d: | xargs -I{} sbatch --depedency afterok:{} final.sh

paste命令将收集所有作业IDS,并将它们写在一行中,用冒号分隔,而xargs将获取结果并将其插入到{}占位符中.有关作业ID的信息是通过管道传递的.

The paste command will gather all job IDS and write them on a single line, colon-separated, while xargs will take the result and insert it at the {} placeholder. The information about the job IDs is passed through pipes.

这篇关于获取作业ID并将其放入bash命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆