da: (bit)
da ([personal profile] da) wrote2009-03-06 10:57 am
Entry tags:

Dear Apple: Fix launchd, document please?

Apparently, cron is deprecated in OSX 10.5.

K, fine. But its replacement, launchd, is a crappy replacement. It has no concept of time ranges (Or does it? Any mac folks with insight to share here?)

I want to replicate this crontab:


0,20,40 8-17 * * * /users/drallen/bin/thing.sh


So, run every 20 minutes between 8am and 5pm 5:40pm.

My preferred answer is to get my crontab entry working, but /var/log/system.log is reporting errors such as Mar 6 10:20:00 scsmac21 com.apple.launchd[1] (0x1000000.cron[64942]): Could not
setup Mach task special port 9: (os/kern) no access
.

Googling finds reports of this same problem and error-message with no solutions offered.

[Edit to add: that error was actually a warning; hiding a $PATH problem that wasn't emailed to me as cron-job errors should be. :-P But it's working now, no help from the OS...]

Google also finds a pile of howtos for launchd from 2005-2006, saying "well, it's not as flexible as cron, but give it time, it's only 1.0." Apple, fix your software!

...I guess I'm stuck with dropping the "8am-5pm" part of it, and writing a launchd plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>scsmac21</string>
        <key>UserName</key>
        <string>drallen</string>
        <key>ProgramArguments</key>
        <array>
                <string>/usr/bin/some_program</string>
                <string>param1</string>
                <string>param2</string>
        </array>
        <key>StartInterval</key>
        <integer>300</integer>
</dict>
</plist>

There, isn't that so much easier?... :-P

Bleh.

[identity profile] sachmet.livejournal.com 2009-03-06 04:44 pm (UTC)(link)
Apple's doc on launchd.plist (http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/ManPages/man5/launchd.plist.5.html#//apple_ref/doc/man/5/launchd.plist) suggests StartCalendarInterval can be configured to take an array of hour/minute pairs, which while tedious to create, would give you back the 8-5 flexibility.

Alternately, you could create a shell wrapper that says "Is it between 8 and 5? No? Quit!" but that seems ridiculous to have to do.

(P.S. Isn't StartInterval of 300... 5 minutes, not 20? Wouldn't you want 1200 instead? Also, I think your cron runs every 20 minutes from 8:00 - 5:40 PM.)
Edited 2009-03-06 16:45 (UTC)

[identity profile] da-lj.livejournal.com 2009-03-06 04:46 pm (UTC)(link)
..ya, I copied someone else's example for the post, didn't change the 300. :)

ckd: (cpu)

[personal profile] ckd 2009-03-06 04:48 pm (UTC)(link)
I don't think cron is so deprecated as to be in danger of removal, because it's part of IEEE Std 1003.1.

I can't help with the "why's cron broken" problem, alas.

[identity profile] da-lj.livejournal.com 2009-03-06 05:58 pm (UTC)(link)
I don't know squat from IEEE standards fights.. context?
ckd: (cpu)

[personal profile] ckd 2009-03-07 08:56 pm (UTC)(link)
IEEE 1003 is POSIX, which is incorporated into Single UNIX Specification 3 and the "UNIX 03" specification. Since Apple is trumpeting their conformance with these specs, crontab is safe.

[identity profile] ng-nighthawk.livejournal.com 2009-03-06 05:23 pm (UTC)(link)
Depricate cron?

I was also thinking that ls, rm, and ln are really kinda old concepts and should be replaced.

Oooh, and while we're at it, let's revamp grep to take completely new and different parameters.

This will help with usability, where usability is equivalent to proprietary offshoots of commonly used functionality to make Mac users more separate from other communities.

Grumbly, grumbly.

[identity profile] da-lj.livejournal.com 2009-03-06 05:56 pm (UTC)(link)
Yeah. That.

As for different grep parameters, at least we're sort of used to that with Solaris/GNU/whatever differences.

Cute userpic. :)

[identity profile] insaint.livejournal.com 2009-03-06 05:25 pm (UTC)(link)
XML is the answer to all life's problems and a few of life's solutions.

[identity profile] http://users.livejournal.com/merle_/ 2009-03-07 04:35 pm (UTC)(link)
Deprecate cron? I'm trying to think of another *nix-based system without cron and failing. Next thing you know they'll deprecate sed and grep. "But you can do the same things in perl, why do you need those old tools?"

XML never seemed like a good idea to me. Human readable is one thing, the ability to have a generic syntax validator is cool, but it adds so much junk. One of my jobs at work is a process that takes a large database extract and rewrites about a fifth of it into XML.. creating a 5G file, which then gets compressed and sent via FTP over an already burdened connection. Daily.

The stuff you can do with XSLT is completely awesome, don't get me wrong. But I can do a heck of a lot with cut/sed/grep/perl on tab-delimited files.