Environment variable usage in LaunchAgents plist files
Hi All, While trying to understand why my console had log entries every two minutes such as this: 3/4/08 10:40:00 com.apple.launchd[1] (0x102450.cron[9834]) Could not setup Mach task special port 9: (os/kern) no access I decided that perhaps it was time to get rid of my cron jobs in favor of launchd.plist entries. So I set out to convert my crontab entry: */2 * * * * /bin/sh "${HOME}/Library/Automation/checkmail.sh" > /dev/ null 2>&1 into a launchd.plist of equal functionality. I presently have: <?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>com.lab.checkmail</string> <key>ProgramArguments</key> <array> <string>/bin/sh</string> <string>/Users/labrown/Library/Automation/checkmail.sh</string> </array> <key>StartInterval</key> <integer>120</integer> </dict> </plist> But I'm unsettled by needing to specify a hard-coded path to my script. Notice, in my crontab entry I was able to access HOME, but when I try that in the plist, it is taken literally (without expanding) and causes obvious problems. HOME is set appropriately, and I can verify that by issuing the 'export' command to launchctl. How does one work around this issue? Thanks, Levi
Levi, launchd does not depend on or otherwise require the machine to have a shell. In fact, Apple's iPhone does not even have /bin/sh. If you want to express environmental variables as command line arguments, please consider having launchd run: /sbin/sh -c $HOME/something/something- else.sh davez On Mar 4, 2008, at 2:24 PM, Levi Brown wrote:
Hi All,
While trying to understand why my console had log entries every two minutes such as this:
3/4/08 10:40:00 com.apple.launchd[1] (0x102450.cron[9834]) Could not setup Mach task special port 9: (os/kern) no access
I decided that perhaps it was time to get rid of my cron jobs in favor of launchd.plist entries. So I set out to convert my crontab entry:
*/2 * * * * /bin/sh "${HOME}/Library/Automation/checkmail.sh" > /dev/ null 2>&1
into a launchd.plist of equal functionality. I presently have:
<?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>com.lab.checkmail</string> <key>ProgramArguments</key> <array> <string>/bin/sh</string> <string>/Users/labrown/Library/Automation/checkmail.sh</string> </array> <key>StartInterval</key> <integer>120</integer> </dict> </plist>
But I'm unsettled by needing to specify a hard-coded path to my script. Notice, in my crontab entry I was able to access HOME, but when I try that in the plist, it is taken literally (without expanding) and causes obvious problems.
HOME is set appropriately, and I can verify that by issuing the 'export' command to launchctl.
How does one work around this issue?
Thanks,
Levi_______________________________________________ launchd-dev mailing list launchd-dev@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/launchd-dev
participants (2)
-
Dave Zarzycki
-
Levi Brown