I want to execute a command when a process dies. I have a solution already, but I'm looking to see if there is a nicer way to do this as a way of further learning BASH. Here is what I have:
$ ps -e | grep scp
7673 pts/1 00:01:17 scp
$ while [ $( ps 7673 2>&1 >/dev/null; echo $? ) = 0 ]; do sleep 1; done; echo "Scp doesn't exist any more"
It works and I've seen uglier solutions. :-) Do you have any improvements on this one or another more elegant solution?
$ (commandToWaitOn; commandToRunAfter) &?
where the optional '&' and puts the pair into the background.
Or if the command was started independently, find the PID and use
wait PID; commandToRunAfter
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With