每分钟运行一次的已启动作业 [英] Launchd job running every minute

查看:61
本文介绍了每分钟运行一次的已启动作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个仅在工作日每天运行一次的启动脚本.但是,一旦我加载了脚本,它就会每分钟运行一次,而不只是按计划运行.无论我是以我自己还是以超级用户身份加载脚本,都会发生这种情况:

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

sudo launchctl load/Library/LaunchDaemons/org.myname.foojob

这是plist文件:

org.myname.foojob

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中启动的原始内置程序来运行此程序.希望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?

推荐答案

我还使用该配置文件在我的 10.4 系统上获得您每分钟一次的行为.

I also get your once-a-minute behavior on my 10.4 system with that config file.

在我的10.4系统上的launchd.plist(5)联机帮助页上说,StartCalendarInterval是整数字典".它看起来像您正在使用的整数字典数组"记录在论坛帖子,该帖子表明该数组功能是在10.5中引入的.

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.

对于10.4,您可能必须为每个要使用的StartCalendarInterval创建一个文件.或者,如果您可以每天使用相同的时间(使星期一与其他时间一致),则可以在plist文件中省略工作日"规范(这样您的脚本将在每天的指定时间运行),并且如果一周中的某一天是周末,那么让你的脚本提前退出 test "$(date +%u)" -lt 6 ||退出0 ).

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).

这篇关于每分钟运行一次的已启动作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆