Get Job id and put them into a bash command

橙三吉。 提交于 2020-06-29 06:42:25

问题


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 

in Order to run the JobIDN I do

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

Then it prints all the jobIDs

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 

exemple

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


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

回答1:


You can store the job ids in a variable and use it for your next command. Something like

jobs=$(seq 1 10 | awk '{ printf ":%s", $1 }')
     # \------/
 # your jobID printing function here

And then

sbatch -d afterok"$jobs" final.sh 



回答2:


You can do it with

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

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.



来源:https://stackoverflow.com/questions/62625865/get-job-id-and-put-them-into-a-bash-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!