Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I should convert this cronjob to a launchctl plist.

Is this possible?

0 8-18 * * 1-5 /usr/bin/curl -s --data "par1=a&par2=b&press=OK" http://mydomain.com/file.php /dev/null
share|improve this question

1 Answer 1

Basically you could save a property list like this as ~/Libary/LaunchAgents/com.superuser.408777.plist, and load it with launchctl load ~/Libary/LaunchAgents/com.superuser.408777.plist or by logging out and back in.

<?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>Label</key>
    <string>com.superuser.408777</string>
    <key>ProgramArguments</key>
    <array>
        <string>curl</string>
        <string>--data</string>
        <string>par1=a&par2=b&press=OK</string>
        <string>http://mydomain.com/file.php</string>
    </array>
<!--    <key>Program</key>
    <string>/absolute/path/to/script</string> -->
    <key>StartCalendarInterval</key>
    <dict>
        <key>Weekday</key>
        <integer>1</integer>
        <key>Hour</key>
        <integer>8</integer>
    </dict>
    <dict>
        <key>Weekday</key>
        <integer>1</integer>
        <key>Day</key>
        <integer>9</integer>
    </dict>
<!--    <key>StartInterval</key>
    <integer>3600</integer> --> this would just run the program arguments every hour
    <key>KeepAlive</key>
    <true/>
</dict>
</plist>

As far as I know, it's not possible to specify date ranges like hours 8-18 and days 1-5, other than listing each combination individually. You could run an external script every hour and exit it depending on the date though.

weekday=$(date +%w)
hour=$(date +%H)
[[ $weekday -le 0 || $weekday -ge 6 || $hour -le 7 || $hour -ge 19 ]] && exit
curl -s --data "par1=a&par2=b&press=OK" http://mydomain.com/file.php /dev/null
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.