Created
November 24, 2015 03:28
-
-
Save boone/f67ec5c7e5b69e6b4a03 to your computer and use it in GitHub Desktop.
Get an email notification when a process completes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ping @boone