launchd plist xml to run job several times a day?

I've been reading about using launchd instead of cron.


For the life of me I can't find out how to run a script at 10AM and 2PM


Can you use:

<key>StartCalendarInterval</key>

<dict>

<key>Hour</key>

<integer>10</integer>

<key>Hour</key>

<integer>14</integer>


or maybe


<key>StartCalendarInterval</key>

<dict>

<key>Hour</key>

<integer>10</integer>

<integer>14</integer>



Maybe I need 2 plists?


If I wanted to run it every X minutes, I can program that into the XML but I don't know how you could do several specified times a day... or for that matter just on Monday and Friday?


I've Googled all night and can't find an example. What is the trick... if there IS a trick?


Thanks,


Al

iMac, Mac OS X (10.7.1)

Posted on Sep 29, 2011 11:40 PM

Reply
21 replies

Oct 3, 2011 2:14 PM in response to al1776

I have few suggestions for your shell script. First, move the script out of your home directory (folder) . There are a number of locations you could put the script- I recommend that you create a directory /usr/local/bin and put the script in there. Change the permissions of the script so only root can run or modify the script. Next, preserve case ->


cd /users/al/documents/wget
#like this
cd /Users/al/Documents/wget


Well, keeping a backup owned by root in your home folder isn't the greatest idea. Maybe create a directory /usr/local/backups/. Last, use absolute paths to your binaries->


/usr/bin/rsync .........
/bin/rm .............
/usr/bin/gunzip .......

Oct 3, 2011 3:43 PM in response to Mark Jalbert

Thanks for the suggestions. They are good ones.... but this is a single-user machine and I'm an old Unix guy so whether a file is owned by root or user, I know how to "work" the system.


I've been running the same script from the same place via cron on a Mac for six years now without a problem and so if it works, don't "fix" it... as they say.


I didn't want to move to launchd, but who is to say how long Apple will keep cron. According to this http://en.wikipedia.org/wiki/Launchd Apple plans to dump it along with a bunch of other old Unix "stuff." Besides, Apple made launchd their brand of "open source" and it would not surprise me if some of the Linux distros pick it up and replace initd, atd, etc.


As for the script in question, all it does is grab a file and re-load a database... which I never use. We do all our production work on our dedicated web server (the so-called cloud) and I keep the local database just in case we lose connectivity or our server takes a hit... which has happend only once in the past seven years... for 90 minutes... since we changed to a server-side paradigm for our databases, banking, faxing, etc.


I suppose that if I ran tons of scriipts it would be a good idea to isolate them, but this is the only one we run locally. All our other scrips are on our FreeBSD server... we dump files and rsync them off to several off-site storate locations... just in case. We run/own the Jaya123 system order-entry/invoicing small-biz service www.jaya123.com which has gained a nice userbase over the past six years we've had it out. Obviously we need to keep our backups in multiple locations separate from weather, quakes, etc.


As for the data we keep locally, it is just for our small insurance agency biz... www.ancins.com and we don't keep any personal/confidential info on our servers like SSNs or medical data. It's just name/address and policy info which we need to access when clients call with questions.


Over the years I've learned to keep things simple and intuitive. I've been doing IT stuff for 30+ years... started with H. Ross Perot and EDS in 1975 so I'm not quite a newbie! I'm older than dirt! My wife says that if I were a lizard I'd be a belt by now! I don't think launchd is "simple" but it has more "horsepower" than cron does and I'll eventually get more used to it... maybe even learn to like it. However, for me the jury is still out as to how stable it is. One thing about cron, once you got it to work (which could be like root canal) it never failed. In the old days we had to install it ourselves... and while not as messy as postfix, it was almost always an all-nighter!


My objection is XML. I would have prefered a plain old config file... similar to php.ini or httpd.conf... there are tons of programs to parse those files and Apple could have used one... insead of an XML parser which by definition is problematic.


Anyway, that's the short answer . 😁




Al

www.ancins.com

www.jaya123.com

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

launchd plist xml to run job several times a day?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.