Skip to content

Instantly share code, notes, and snippets.

@boone
Created November 24, 2015 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boone/f67ec5c7e5b69e6b4a03 to your computer and use it in GitHub Desktop.
Save boone/f67ec5c7e5b69e6b4a03 to your computer and use it in GitHub Desktop.
Get an email notification when a process completes
#!/bin/bash
# Watch a running process and notify by email when it's done
# usage ./pcomplete.sh pid email
# or nohup ./pcomplete.sh pid email & to background it
# TODO verify args
# TODO timeout option
# TODO include abiity to detach and run in the background
pid=$1
email=$2
message="Process $pid on `hostname` has finished."
echo "Monitoring $pid..."
while true
do
psout=`ps -p $pid | tail +2`
if [[ -z "$psout" ]]
then
break
fi
sleep 1
done
echo "$message" | mail -s "Process Complete" "$email"
@ruyrocha
Copy link

ruyrocha commented Dec 1, 2015

while true
do
  kill -0 $pid ; [[ $? -eq 0 ]] && break
done

ping @boone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment