如何在 crontab 中取消设置 MAILTO?
正如 crontab 的文档所解释的,如果 < code>MAILTO 未设置,则输出将发送至 cron 的所有者,如果 MAILTO
设置且不为空,则表示邮件应发送到何处,如果已设置且为空,没有设置邮件。
在 cron 中设置诸如 MAILTO
之类的环境变量后,有什么方法可以取消设置它吗?我已经尝试过明显的 unset MAILTO
和 MAILTO=
但 crontab -e
不接受这些。
我有一个解决方法(确保我想要的默认邮件行为的所有内容都出现在原始邮件之前)。不过,我正在编写一个脚本来编写 cron 作业,如果能够设置/取消设置 MAILTO
而无需重新排序命令,那就太好了。
如果重要的话,这将在 Linux 系统上的 Vixie cron 下运行。
编辑:澄清。我希望将作业邮寄给所有者或 MAILTO
中指定的用户。我不希望出现 MAILTO=''
导致的工作根本没有邮寄给任何人的行为。
As the documentation for crontab explains, if MAILTO
is not set then output goes to the owner of the cron, if MAILTO
is set and not empty, it says where mail should go, and if it is set and empty, no mail is set.
Is there any way to unset environment variables like MAILTO
in cron after it has already been set to something? I already tried the obvious unset MAILTO
and MAILTO=
but crontab -e
does not accept those.
I have a workaround (make sure that everything that I want default mailing behavior comes before the original). However I'm writing a script to write cron jobs, and it would be nice to be able to set/unset MAILTO
without having to reorder commands.
If it matters, this will be running on a Linux system under Vixie cron.
Edit: Clarification. I want jobs to either get mailed to the owner or to a user named in a MAILTO
. I don't want the behavior that MAILTO=''
causes where jobs get mailed to nobody at all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要相信无论如何都可以取消它:您可能只想将不希望通过电子邮件发送到
/dev/null
的命令的输出通过管道传输。Do not believe there is anyway to unset it: you might want to just pipe the output of the commands you don't want emailed into
/dev/null
.