Launchd job running every minute

2019-06-03 18:20发布

问题:

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?

回答1:

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



标签: macos launchd