yourcommand 2>&1 | mail -s "yourcommand is done" yourname@example.com
2>& 1位表示“让我的错误像常规输出一样”,其余的则说“采取常规输出并将其邮寄给我一个不错的主题行”
请注意,它不适用于csh系列shell,只能使用Bourne(sh,bash,ksh …),AFAIK.因此,在#!/ bin / sh或#!/ bin / bash下运行. (N.B.您可以使用命令|& mail …在csh中管道两个描述符,但只有疯子才能使用csh编写脚本.)
更新:
How would I write the errors to a log file and then just email my self on completion?
如果你的意思是通过电子邮件发送它已经完成的事实,
yourcommand 1>/dev/null 2>mylogfile ; (echo "done!" | mail -s "yourcommand is done")
如果你的意思是只是通过电子邮件发送错误(在这种情况下你不需要日志文件)(修复为@Trey说),
yourcommand 2&>1 1>/dev/null | mail -s "yourcommand is done" yourname@example.com