up vote 1 down vote favorite
2
share [g+] share [fb]

I have the following launchctl command as a .plist file. It's loaded and set to run once a day but, it needs to run as root and I'm not sure how to verify this.

Also, this cron job basically CDs into a directory and runs a command. I'm sure launchd has a better way of specifying the directory where it's supposed to run the command.

How do I know it's run as root and is there a better way to write this?

<?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>dev.project.frontpage.feedparser</string>
    <key>ProgramArguments</key>
    <array>
    	<string>cd</string>
    	<string>/Users/eman/src/project/trunk/includes/;</string>
    	<string>./feed-parser.php</string>
    	<string>-c</string>
    	<string>./feed-parser-config.xml</string>
    </array>
    <key>QueueDirectories</key>
    <array/>
    <key>StartCalendarInterval</key>
    <dict>
    	<key>Hour</key>
    	<integer>12</integer>
    	<key>Minute</key>
    	<integer>0</integer>
    </dict>
    <key>WatchPaths</key>
    <array/>
</dict>
</plist>
link|improve this question
feedback

2 Answers

up vote 5 down vote accepted

What folder is the .plist stored in?

launchd runs Daemons (/Library/LaunchDaemons or /System/Library/LaunchDaemons) as root, and will run them regardless of whether users are logged in or not. Launch Agents (/Library/LaunchAgents/ or ~/Library/LaunchAgents/) are run when a user is logged in as that user. You can not use setuid to change the user running the script on daemons.

Because you will want to add it in /Library/LaunchDaemons you will want to make sure you load it into launchd with administrator privileges (eg. sudo launchctl load -w /Library/LaunchDaemons/com.apple.samplelaunchdscript.plist)

Check out man launchd for more information.

link|improve this answer
Thank you. This is exactly what I was looking for as far as answering the root issue. The script is in /Library/LaunchDaemons so it was already running as root. – Emmanuel Mwangi Sep 5 '09 at 17:59
feedback

Have you tried using one of the launchd editors?

To make sure it is run as root, I'm pretty sure launchd will run the programs as root. Ever think of giving ownership of the script to root using chmod? This way, it won't run unless run as root. You need to then verify that it runs.

chmod root:admin script_to_run_by_launchd
link|improve this answer
I did use Lingon to write this script. And I can fonfirm it works well in Leopard. – Emmanuel Mwangi Sep 5 '09 at 17:57
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.