You can use the trap
command to define an exit function and notify you:
function exit_shell {
echo -e "Goodbye!\a"
}
trap exit_shell 1 2 3 4 5 6 7 8 10 11 12 13 14 15
# And the rest of your script goes here...
This way, almost any signal (except for 9
or KILL
which can't be trapped) will cause your function to execute. The \a
will sound the terminal bell in a hardware independent manner (although it's almost always ASCII 0x07).
However, why limit yourself to a mere bell which might not sound. You could send yourself an SMS text using the mail
command and your cell phone service provider's email gateway. For example, in Verizon you can send an email to phone@vtext.com where phone is your phone number without dashes.
function exit_shell {
echo -e "Goodbye!" | mailx -s "Command failed!" $phone@vtext.com
}
trap exit_shell 1 2 3 4 5 6 7 8 10 11 12 13 14 15
Or, you can find a command line Twitter client or Facebook client and update all of your friends with your status.