There's no any built in way to do this. However I'd run just a oneliner to achieve what you need.
However you need to know your process id of the bg process (in your case wget
). You could run ps aux | grep wget
Once you have the PID, You can use wait
. However this doesn't work if you closed the previous shell or session.
In that case I'd use ps -p PID
with a while
loop to fire sleeps while the process is active and after process stopped while
statement ends and shell will execute your sendmail
command.
Full code goes as:
while ps -p YOUR-PID > /dev/null; do sleep 1; done && echo "Subject: WGET DONE!" | sendmail user@domain.com
summery of above code: while your selected PID process runs while
condition becomes true and loop keeps executing sleep 1
and it checks for it's condition every one second. However if the process ends while
condition becomes false and the while loop will end. And the shell will execute the command after && which is sendmail