在Mac上开始使用cronjobs

Ada*_*dam 6 macos terminal cron crontab

我正在尝试熟悉cron作业,我认为我得到了基本的想法(调度,语法等),但是,我似乎无法在我的Mac上使用终端 - 我在哪里找到了crontab的?我应该如何引用脚本的路径?

我想要做的是在远程机器上打一个PHP脚本(http:// ..) - 这有可能吗?

Rya*_*ght 8

键入crontab -e以编辑cron表并crontab -l列出当前内容.键入man 1 crontab有关该命令man 5 crontab的更多信息以及有关cron表文件格式的更多信息.

例如,要在每天10:00a下载stackoverflow页面,请运行crontab -e,输入此行,然后保存/退出.输出将写入主目录中的文件.

0 10 * * * /usr/bin/curl -s http://stackoverflow.com > ~/stackoverflow.html
Run Code Online (Sandbox Code Playgroud)


sas*_*ont 5

要开始启动(而不是cron),您需要首先创建一个空.plist文件,例如local.mytask.plist,将其放置在某个地方。~/Library/LaunchAgents可能是个好地方。在文本编辑器中打开它,然后复制下面的代码

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<false/>
<key>Label</key>
<string>local.mytask</string>
<key>ProgramArguments</key>
<array>
<string>/opt/local/bin/wget</string>
<string>http://someserver/somepage.php</string>
</array>
<key>StartInterval</key>
<integer>300</integer>
<key>RunAtLoad</key>
<true />
<key>StandardErrorPath</key>
<string>/dev/null</string>
<key>StandardOutPath</key>
<string>/dev/null</string>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)

然后从命令行“激活”文件:

sudo launchctl load /Users/my_username/Library/LaunchAgents/local.mytask.plist
Run Code Online (Sandbox Code Playgroud)

要使其自动加载,请创建~/.launchd.conf同一行(减sudo launch)的文件

load /Users/my_username/Library/LaunchAgents/local.mytask.plist
Run Code Online (Sandbox Code Playgroud)

以上说明已从www.davidlanier.com复制而来,并在此处重新发布以供您参考。