macos mac os 10.6 雪豹下的 cron 作业

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1999775/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 06:38:38  来源:igfitidea点击:

cron jobs under mac os 10.6 snow leopard

macoscronosx-snow-leopardcrontab

提问by jtrim

I'm trying to set up an automated svn commit to run semi-hourly under mac os 10.6, but the crontabs i'm adding to cron don't seem to be valid and/or don't seem to even be looked at by cron. For testing i made a simple crontab and script:

我正在尝试设置一个自动 svn commit 在 mac os 10.6 下每半小时运行一次,但是我添加到 cron 的 crontabs 似乎无效和/或似乎甚至没有被查看克朗。为了测试,我做了一个简单的 crontab 和脚本:

Crontab: */2 * * * * /Users/username/crontest

定时盘: */2 * * * * /Users/username/crontest

where username is replaced with my system username, thus pointing to my home directory (and yes, those really are tabs between each value - they aren't faithfully reproduced in the codesection)

其中 username 被我的系统用户名替换,从而指向我的主目录(是的,那些确实是每个值之间的选项卡 - 它们没有在该code部分忠实地复制)

I'm running a crontab -rfirst, then running crontab .mycrontabthat contains the above line. crontab -lspits out the line above, and running ps -A | grep cronshows /usr/sbin/cronrunning, which I assume is the cron daemon under mac os x. The /Users/username/crontestscript is simply appending a line of text to a text file, as such:

crontab -r首先运行,然后运行crontab .mycrontab包含上述行的内容。 crontab -l吐出上面那行,runningps -A | grep cron显示/usr/sbin/cron正在运行,我假设是mac os x下的cron守护进程。该/Users/username/crontest脚本只是将一行文本附加到文本文件中,如下所示:

echo "hi" >> /Users/username/crontest.txt

echo "hi" >> /Users/username/crontest.txt

What gives? I'm stumped.

是什么赋予了?我难住了。

回答by jtrim

Oops...I was missing the newline character at the end of the cron job. That seems to have fixed it.

糟糕...我在 cron 作业结束时错过了换行符。这似乎已经解决了它。

回答by Ned Deily

Although the preferred method on OS X for running automated jobs is launchd, cronis still supported. Chances are you have a permissions problems with your script; make sure it has execute permission.

尽管 OS X 上运行自动化作业的首选方法是launchdcron但仍受支持。您的脚本可能存在权限问题;确保它具有执行权限。

Also, */2means every two minutes, not semi-hourly. Try setting the minutes field with a list of minutes:

此外,*/2意味着每两分钟一次,而不是每半小时一次。尝试使用分钟列表设置分钟字段:

0,30    *   *   *   *   /Users/username/crontest

Works for me on 10.6.

在 10.6 上对我有用。