3

I've always been a crontab guy. Recently I have decided to make the switch to Apple's launchd processes, and I am unable to get my first plist to run.

  1. The plutil -lint command tells me the plist is formatted correctly. Actually, it outputs "OK".

  2. I have run the bash script manually and confirmed that it properly operates when manually initiated.

  3. I have loaded the file using launchctl load and received the response "already loaded" on repeated attempts to do the same.

The problem must be in my PLIST definition. Please help me spot the error.

I expect this to run with the following conditions:

  • Only while the user jaredclemence is using the system
  • Once immediately on login
  • Every 15 minutes thereafter
  • Change Directory to /Library/WebServer/Documents/medface/ before running the script.

The plist file is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>org.pediatricheartcenter.medface.crons</string>
        <key>User</key>
        <string>jaredclemence</string>
        <key>ProgramArguments</key>
        <array>
                <string>/User/jaredclemence/runMedfaceSchedTasks.batch</string>
        </array>
        <key>WorkingDirectory</key>
        <string>/Library/WebServer/Documents/medface</string>
        <key>StartInterval</key>
        <integer>900</integer>
        <key>RunAtLoad</key>
        <true/>
</dict>
</plist>

Notes:

  • I have stored the file in ~/Library/LaunchAgents/org.pediatricheartcenter.medface.crons.plist
  • A previous version of the file used Program instead of ProgramArguments with a <string> value instead of an array.
  • 1
    As an initial step in debugging, I'd suggest setting <key>StandardOutPath</key> and <key>StandardErrorPath</key> - I'd suggest ~/Library/Logs/org.pediatricheartcenter.medface.crons.stdout (and ...stderr) as that's the usual logging location for launch agents, but use whatever works for you. Add echo or printfs to the start and end of runMedfaceSchedTasks.batch, and see what the logs say after you launchctl load your plist. – John N Feb 3 '17 at 17:41
  • 1
    On further research, I discovered that launchd writes errors to the system.log. I found the answer there! Thank you, John! – Jared Clemence Feb 3 '17 at 17:44
4

Launchd writes errors to system.log. Using Console, I viewed the log. There, launchd told me that it did not like my User key value. I removed the User - jaredclemence key-value pair, and loaded the plist again. It then told me the batch program did not exist and I then noticed the error in the file path. /User should be /Users

By removing the User setting and correcting the file path, I was able to fix the problem. Now, running ps -ef | grep 'runMed', I am able to see that the batch file is currently executing.

SUCCESS!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .