每分钟运行一次启动作业
我正在尝试编写一个仅在工作日每天运行一次的 launchd 脚本。但是一旦我加载脚本,它就会每分钟运行一次,而不仅仅是按计划运行。无论我以自己的身份还是以超级用户的身份加载脚本,都会发生这种情况:
launchctl load ~/Library/LaunchAgents/org.myname.foojob
或
sudo launchctl load /Library/LaunchDaemons/org.myname.foojob
这是 plist 文件:
org.myname.foojob
<!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>Label</key>
<string>org.myname.foojob</string>
<key>ProgramArguments</key>
<array>
<string>/Users/myname/bin/foojob.sh</string>
</array>
<key>StartCalendarInterval</key>
<array>
<dict>
<key>Hour</key>
<integer>16</integer>
<key>Minute</key>
<integer>00</integer>
<key>Weekday</key>
<integer>1</integer>
</dict>
<dict>
<key>Hour</key>
<integer>16</integer>
<key>Minute</key>
<integer>00</integer>
<key>Weekday</key>
<integer>2</integer>
</dict>
<dict>
<key>Hour</key>
<integer>16</integer>
<key>Minute</key>
<integer>00</integer>
<key>Weekday</key>
<integer>3</integer>
</dict>
<dict>
<key>Hour</key>
<integer>16</integer>
<key>Minute</key>
<integer>00</integer>
<key>Weekday</key>
<integer>4</integer>
</dict>
<dict>
<key>Hour</key>
<integer>16</integer>
<key>Minute</key>
<integer>00</integer>
<key>Weekday</key>
<integer>5</integer>
</dict>
</array>
</dict>
</plist>
我正在使用 Mac OSX 10.4 中原始的内置 launchd 来运行它。希望这只是 plist 文件中的一些小问题。有人有主意吗?
I am attempting to write a launchd script that runs once a day, on weekdays only. But once I load the script, it runs every minute instead of just on-schedule. This happens whether I load the script as myself or as superuser:
launchctl load ~/Library/LaunchAgents/org.myname.foojob
or
sudo launchctl load /Library/LaunchDaemons/org.myname.foojob
This is the plist file:
org.myname.foojob
<!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>Label</key>
<string>org.myname.foojob</string>
<key>ProgramArguments</key>
<array>
<string>/Users/myname/bin/foojob.sh</string>
</array>
<key>StartCalendarInterval</key>
<array>
<dict>
<key>Hour</key>
<integer>16</integer>
<key>Minute</key>
<integer>00</integer>
<key>Weekday</key>
<integer>1</integer>
</dict>
<dict>
<key>Hour</key>
<integer>16</integer>
<key>Minute</key>
<integer>00</integer>
<key>Weekday</key>
<integer>2</integer>
</dict>
<dict>
<key>Hour</key>
<integer>16</integer>
<key>Minute</key>
<integer>00</integer>
<key>Weekday</key>
<integer>3</integer>
</dict>
<dict>
<key>Hour</key>
<integer>16</integer>
<key>Minute</key>
<integer>00</integer>
<key>Weekday</key>
<integer>4</integer>
</dict>
<dict>
<key>Hour</key>
<integer>16</integer>
<key>Minute</key>
<integer>00</integer>
<key>Weekday</key>
<integer>5</integer>
</dict>
</array>
</dict>
</plist>
I'm running this with the original built-in launchd in Mac OSX 10.4. Hopefully it's just something slightly wrong with the plist file. Anybody have an idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还通过该配置文件在我的 10.4 系统上获得了您每分钟一次的行为。
我的 10.4 系统上的 launchd.plist(5) 联机帮助页说 StartCalendarInterval 是一个“整数字典”。看起来您正在使用的“整数字典数组”记录在 10.6 launchd.plist(5) 联机帮助页。我发现一个 论坛帖子表明数组功能是在 10.5 中引入的。
对于 10.4,您可能必须为要使用的每个 StartCalendarInterval 创建一个文件。或者,如果您可以每天使用相同的时间(使星期一与其他时间保持一致),您可以在 plist 文件中省略工作日规范(以便您的脚本将在每天的指定时间运行)并且然后,如果一周中的某一天是周末,则让脚本提前退出
test "$(date +%u)" -lt 6 ||退出 0
)。I also get your once-a-minute behavior on my 10.4 system with that config file.
The launchd.plist(5) manpage on my 10.4 system says that StartCalendarInterval is a “dictionary of integers”. It looks like the “array of dictionary of integers” that you are using is documented in the 10.6 launchd.plist(5) manpage. I found a forum post that indicates that the array feature was introduced in 10.5.
For 10.4, you will probably have to create one file for each StartCalendarInterval you want to use. Or, if you can stand to use the same time each day (bring Monday in line with the others), you could leave out the Weekday specification in the plist file (so that your script would be run at the specified time every day) and then make your script exit out early if the day of the week is a weekend day
test "$(date +%u)" -lt 6 || exit 0
).