linux邮件写完如何退出,linux – 如何在后台运行命令并在完成后通过电子邮件通知我...

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值