yourcommand 2>&1 | mail -s "yourcommand is done" [email protected]
The 2>&1
bit says "make my errors like the regular output", and the rest says "take the regular output and mail it to me with a nice subject line"
Note that it doesn't work in csh
family of shells, only Bourne (sh
, bash
, ksh
...), AFAIK. Thus, run under #!/bin/sh
or #!/bin/bash
. (N.B. You can pipe both descriptors in csh
using yourcommand |& mail ...
, but only a madman writes scripts using csh
.)
UPDATE:
How would I write the errors to a log file and then just email my self on completion?
if you mean just email the fact that it is done,
yourcommand 1>/dev/null 2>mylogfile ; (echo "done!" | mail -s "yourcommand is done")
if you mean just email the errors (in which case you don't need the log file) (fixed as @Trey said),
yourcommand 2&>1 1>/dev/null | mail -s "yourcommand is done" [email protected]