tags:

views:

64

answers:

1

Hi,

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?

+6  A: 

$ (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
dmckee