每分钟运行一次启动作业

发布于 2024-08-12 09:17:21 字数 2539 浏览 4 评论 0原文

我正在尝试编写一个仅在工作日每天运行一次的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南七夏 2024-08-19 09:17:21

我还通过该配置文件在我的 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文