问题描述
从旧Mac迁移到新Mac.
Migrating from an old mac to a new one.
尝试迁移旧Mac上的用户crontab.
Trying to migrate the user crontab I had on the old mac.
现在,我知道我可以通过创建/etc/crontab来使cron运行-但考虑到苹果已经弃用了cron,因此建议使用launchd-我想我应该将crontab迁移到启动的plist文件中.总是很高兴学习新东西:)
Now I know I can probably get cron to run by creating /etc/crontab - but given that apple has deprecated it in favour of launchd - I thought I'd take a swing at migrating my crontab to launchd plist files. Always fun to learn something new :)
crontab并不难-我倾向于设置可以完成工作的shell脚本,然后只在计划的时间调用它们.
The crontab isn't that hard - I tend to set up shell scripts that do the work and then just call them at scheduled times.
我可以同时从plist中调用这些命令-没问题.
I can call these fine from the plist at the same times - no issues.
但是-在我的crontab的顶部,我有MAILTO = my-gmail-email-address-因此,与其在框的邮件后台处理中向本地用户发送邮件,不如将其发送给gmail.
But - at the top of my crontab I had MAILTO=my-gmail-email-address - so that instead of sending mail to the local user on the box's mail spool it sent them to gmail for me.
我看不到您可以为启动的plist文件配置它.
I can't see that you can configure this for a launchd plist file.
那么-在我修改所有脚本以将所有输出重定向到tmp文件然后邮寄tmp文件之前(必须在很多脚本中这样做),有没有办法在启动级别上做到这一点? /p>
So - before I go modify all my scripts to redirect all output to tmp files then mail the tmp file (would have to do this in quite a few scripts) - is there a way to do this at the launchd level?
推荐答案
恐怕launchd(8)不支持开箱即用地发送stdout/stderr.解决方法:
I'm afraid launchd(8) does not support mailing of stdout/stderr out of the box. Here's a workaround:
通过StandardOutPath
和StandardErrorPath
将输出重定向到专用目录中的文件.然后设置一个作业,以邮寄该目录中的每个文件.用QueueDirectories
键触发此作业.确保此脚本在邮寄文件后将其删除.
Redirect output via StandardOutPath
and StandardErrorPath
to files in a dedicated directory. Then setup a job which mails every file in this directory. Trigger this job with the QueueDirectories
key. Make sure this script removes the files after mailing them.
这篇关于将Cron转换为已启动-MAILTO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!