yourcommand 2>&1 | mail -s "yourcommand is done" yourname@example.com
Bit 2>&1 says: "Make my mistakes look like regular output," and the rest say: "Take the usual output and send it to me with a good storyline."
Note that this does not work in the csh shell family, only Bourne ( sh , bash , ksh ...), AFAIK. So run #!/bin/sh or #!/bin/bash . (NB You can pass both descriptors to csh using yourcommand |& mail ... , but only a crazy yourcommand |& mail ... writes scripts using csh .)
UPDATE:
How can I write errors to a log file and then just send my completion by email?
if you mean just emailing the fact that this is done,
yourcommand 1>/dev/null 2>mylogfile ; (echo "done!" | mail -s "yourcommand is done")
if you mean just send error messages (in this case you do not need a log file) ( fixed as @Trey ),
yourcommand 2&>1 1>/dev/null | mail -s "yourcommand is done" yourname@example.com
source share