5 Replies Latest reply: Sep 4, 2010 3:47 PM by GreybeardCT
Todd Heberlein1 Level 1 (30 points)
Continuing testing with launchd. It's driving me crazy. I feel like it is broken. I am trying to run a program every 5 minutes using StartCalendarInterval.

(0) I have a Mac Mini with very few process running (I have Terminal app up with two windows and the web server running).

(1) I created a very simple UNIX program to create a file (with the file name derived in part from the system time).

(2) After, say 3:05 pm I do an "ls" in the directory where the UNIX program should write the file, but it isn't there. However, if I immediately do another "ls", the file is there with the current time.

I've even waited over 2 minutes after the scheduled run of the program -- do an "ls" (new file is not there) followed immediately by another "ls" and there is the file.

It almost seems that if I don't initiate some action (e.g., running the "ls" command), launchd will not run my program. It is as if launchd is asleep at the switch until something happens (a new process is created?).

Should I give up on launchd for scheduling operations on an otherwise quiet machine?

Mac Mini 2.4 GHz Intel Core 2 Duo, Mac OS X (10.6.4)
  • BobHarris Level 6 (17,699 points)
    I do not know launchd, however, if you post your launchd .plist file between a pair of
     tags,


    ...
    ... your launchd .plist here ...
    ...
    {code}

    maybe someone that is into launchd will offer some advice, or spot a flaw in your .plist.
  • Todd Heberlein1 Level 1 (30 points)


    <?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.netsq.TimedTest</string>
    <key>ProgramArguments</key>
    <array>
    <string>/etc/security/timed_test</string>
    </array>
    <key>StartCalendarInterval</key>
    <array>
    <dict>
    <key>Minute</key>
    <integer>00</integer>
    </dict>
    <dict>
    <key>Minute</key>
    <integer>05</integer>
    </dict>
    <dict>
    <key>Minute</key>
    <integer>10</integer>
    </dict>
    <dict>
    <key>Minute</key>
    <integer>15</integer>
    </dict>
    <dict>
    <key>Minute</key>
    <integer>20</integer>
    </dict>
    <dict>
    <key>Minute</key>
    <integer>25</integer>
    </dict>
    ...

    <dict>
    <key>Minute</key>
    <integer>50</integer>
    </dict>
    <dict>
    <key>Minute</key>
    <integer>55</integer>
    </dict>
    </array>
    <key>UserName</key>
    <string>root</string>
    </dict>
    </plist>
  • Todd Heberlein1 Level 1 (30 points)
    Here are some of the file times and file names I have been getting:

    15:45 time_15:45:19 <-- 19 second late
    15:42 time_15:42:15 <-- 2 minutes & 15 seconds late
    15:38 time_15:38:21 <-- 3 minutes & 21 seconds late
    15:31 time_15:31:53 <-- 1 minute & 53 seconds late
    15:26 time_15:26:21 <-- 1 minute and 21 seconds late

    Before I added this test plist file I had a plist file that would rotate the audit logs at 1 minute after midnight every day. It was over 5 hours late this morning.
  • Baumkartoffel Level 1 (140 points)
    Todd, have you tried adding


    <key>KeepAlive</key>
    <true/>


    within the <dict> element of your XML property list?
  • GreybeardCT Level 1 (5 points)
    First, I wouldn't use StartCalendarInterval, I would use StartInterval ... see this article: http://www.devdaily.com/mac-os-x/launchd-plist-examples-startinterval-startcalen darinterval

    Second, are you loading and unloading the plist using launchctl? What directory are you putting the plist in?

    After you have loaded it with launchctl try

    launchctl list com.netsq.TimedTest