Lord of the Rant.
Formerly turtle2472 Join Date: Mar 2005
Location: Upstate South Carolina
|
So I’m working to migrate from cron to launchd and can't seem to figure out how to make a one-liner cron a new .plist for LaunchDaemons. Anyone good with this? For one of my jobs I ended up making a bash script and calling it. This seems like a horrible waste of resources though since it only needs to be a one-liner:
Code:
* * * * * loadavg1=`sysctl -n vm.loadavg|awk '{print $2}'`;curl -d "email=XXXXXXX&stat=Load Average&value=$loadavg1" http://api.stathat.com/ez > /dev/null 2>&1; unset loadavg1 This ended up being this .plist:Code:
<?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>loadavg_stathat</string>
<key>UserName</key>
<string>root</string>
<key>Program</key>
<string>/Users/User/Dropbox/Documents/code/StatHat.command</string>
<key>StartInterval</key>
<integer>60</integer>
<key>Debug</key>
<false/>
<key>AbandonProcessGroup</key>
<true/>
</dict>
</plist> The code for that target file is:Code:
#!/bin/bash
loadavg1=`sysctl -n vm.loadavg|awk '{print $2}'`
curl -d "email=xxxxxxxxx&stat=Load Average&value=$loadavg1" http://api.stathat.com/ez Doesn't all that seem overkill for a single line cron command? Similarly I have an rsync to run that I just don't want to put in a script for a basic one-liner, this would be a simple cron too: Code:
* 4,10,16,22 * * * rsync -avzP --exclude=Cache User@192.168.xxx.xxx:/Volumes/MCMaps/an/ /Library/WebServer/mcmaps/ Also, I have looked at Apple's man page, and even this on creating the jobs.Louis L'Amour, “To make democracy work, we must be a nation of participants, not simply observers. One who does not vote has no right to complain.” Visit our archived Minecraft world! | Maybe someday I'll proof read, until then deal with it. |
quote |
Lord of the Rant.
Formerly turtle2472 Join Date: Mar 2005
Location: Upstate South Carolina
|
So is it safe to assume that no one really understands how to use launchd then?
|
quote |
Space Pirate
Join Date: May 2004
Location: Atlanta
|
I do not, if that helps.
If it's not Brad or Chucker then give up ... |
quote |
‽
|
I don't really understand your question.
|
quote |
Lord of the Rant.
Formerly turtle2472 Join Date: Mar 2005
Location: Upstate South Carolina
|
As simply put as I can; how do I make this:
Code:
* 4,10,16,22 * * * rsync -avzP --exclude=Cache User@192.168.xxx.xxx:/Volumes/MCMaps/an/ /Library/WebServer/mcmaps/ or this:Code:
* * * * * loadavg1=`sysctl -n vm.loadavg|awk '{print $2}'`;curl -d "email=XXXXXXX&stat=Load Average&value=$loadavg1" http://api.stathat.com/ez > /dev/null 2>&1; unset loadavg1 a .plist for launchd.Expanded a little father, I don't want to have a .plist that calls a different script. I want it all in one job .plist just like that cron is a one liner. Louis L'Amour, “To make democracy work, we must be a nation of participants, not simply observers. One who does not vote has no right to complain.” Visit our archived Minecraft world! | Maybe someday I'll proof read, until then deal with it. |
quote |
‽
|
Yeah, so your question isn't so much how to make it work, but how to avoid having separate .plist and .sh files? The first one is probably feasible using ProgramArguments, like so:
Code:
<key>Program</key>
<string>rsync</string>
<key>ProgramArguments</key>
<array>
<string>-avzP</string>
<string>--exclude=Cache</string>
…
</array> The second one may be possible, but not without some escaping tricks. You're assuming the existence of a shell there; launchd isn't one. Have a separate .sh file for it. |
quote |
Lord of the Rant.
Formerly turtle2472 Join Date: Mar 2005
Location: Upstate South Carolina
|
Now that makes sense. It didn't occur to me that there was no shell assumed. Thank you for the example. I'm sure I can run with this now.
Louis L'Amour, “To make democracy work, we must be a nation of participants, not simply observers. One who does not vote has no right to complain.” Visit our archived Minecraft world! | Maybe someday I'll proof read, until then deal with it. Last edited by turtle : 2014-03-12 at 17:41. Reason: Edited the first word because I actually noticed after the fact that I had put the wrong thing in there even though I was barely awake when I typed this this early morning. |
quote |
Posting Rules | Navigation |
|
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
launchd help needed. | turtle | Programmer's Nook | 8 | 2012-06-05 21:43 |
CSS help needed | torifile | Programmer's Nook | 12 | 2008-09-25 17:37 |
Apple Opens Up: Kernel, Mac OS Forge, iCal Server, Bonjour, Launchd | scratt | Programmer's Nook | 12 | 2006-08-09 23:18 |
Some info needed about DVD -/+ R | Phoenix | Genius Bar | 3 | 2005-03-31 23:59 |
Needed Ram | MacDude15 | Apple Products | 10 | 2005-01-22 23:51 |