问题
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