在 Mac 上开始使用 cronjobs [英] Getting started with cronjobs on a Mac
问题描述
我正在尝试熟悉 cron 作业,并且我想我了解了基本概念(调度、语法等),但是,我似乎无法在我的 mac 上用终端正确地完成它 - 到底在哪里做我找到了Crontab?我应该如何引用脚本的路径?
I'm trying to get familiar with cron jobs, and I think I get the basic idea (scheduling, syntax, etc), But, I can't seem to get it right on my mac with Terminal - where exactly do I find the Crontab? How should I reference the paths to scripts?
我想要做的是在远程机器上运行一个 php 脚本(http://...)- 这可能吗?
What I'm trying to do is hit a php script on a remote machine (http://...) - Is that possible at all?
推荐答案
要开始使用 launchd(而不是 cron),您需要先创建一个空的 .plist
文件,例如 local.mytask.plist
并将其放在某处.~/Library/LaunchAgents
可能是个好地方.在文本编辑器中打开并复制下面的代码
To get started with launchd (instead of cron) you'll want to first create an empty .plist
file, for example local.mytask.plist
and put it somewhere. ~/Library/LaunchAgents
is probably a good place. Open that in text editor and copy in the code below
<?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>
然后从命令行激活"文件:
Then "activate" the file from the command line:
sudo launchctl load /Users/my_username/Library/LaunchAgents/local.mytask.plist
为了让它自动加载,创建一个 ~/.launchd.conf
文件与同一行(减去 sudo launch
)
To make it load automatically, create a ~/.launchd.conf
file with the same line (minus sudo launch
)
load /Users/my_username/Library/LaunchAgents/local.mytask.plist
以上说明复制自 www.davidlanier.com 并在此处重新发布供您参考.
The above instructions above have been copied from www.davidlanier.com and reposted here for your reference.
这篇关于在 Mac 上开始使用 cronjobs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!