When I launch a long-running process I like to forget about it, but how do I know when it’s finished?
You can of course have it send an email after it finishes:
long_process; echo "finished" |mail -s "finished" you@somewhere.com
For this to work, it’s very useful to have ssmtp or msmtp configured, so you have a sane, working local SMTP agent.
You can also send the notification only if the command succeeds:
long_process && echo "finished" |mail -s "finished" you@somewhere.com
OK, so you forgot to add the notification to your initial command line. You can use a loop to monitor a particular process and notify you when it’s done.
In this case I’ll be monitoring an instance of netcat. Determining the process name is up to you 🙂 The delimiters $ and ^ look for the executable names only.
The while loop will run while the process exists; once the process disappears the loop continues with the next instruction in the line, which is popping up an alert on the desktop and then sending an email. So if I’m not glued to the desktop, I’ll still get an email when this is done.
while pgrep $nc^; do sleep 5; done; alert; (echo "finished" |mail -s "finished" you @somewhere.com)