Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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
    
Thumbs down to Apple for not supporting commas or dashes for specifying ranges and days. It makes for a very long and difficult plist file. I submitted a feedback report on OSX to Apple over this just now. – Volomike Apr 14 at 23:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .