Reputation: 2637
I would like a bash script to execute a command (which reports status information) when a certain job finishes. I am running (with a script) a number of programs and send them to background using nohup. When they finish I would like to execute a script which collects information and reports it. Note that I am aware that I can have a for loop with sleep which checks actively if the pid is still in the jobs list. But I am wondering whether there is a way to tell the system to run this script e.g. by adding options to nohup.
Upvotes: 0
Views: 929
Reputation: 359995
This might work for you:
{script; report} &
disown -h
or, to make it conditional:
{script && report} &
disown -h
You could even do:
{script && report || fail} &
disown -h
Upvotes: 0
Reputation: 36229
Start your jobs in a function, and the function in background.
task1plus () {
task1
whenFinished1
}
task2plus () {
task2
whenFinished2
}
task3plus () {
task3
whenFinished3
}
task1plus &
task2plus &
task3plus &
Upvotes: 0
Reputation: 27343
You could nohup
a script that runs the command that you want to run and then runs the post-completion job afterward.
For example, create runtask.sh
:
runjob
collect_and_report
and then:
% nohup runtask.sh
Upvotes: 1