Launchd scheduled job always returns exit code:1

Hi, I have a scheduled job that calls a bash script and applescript, but in the console log, the exit code is always 1:

May 31 09:33:00 Constellation launchd: backup.work: exited with exit code: 1
May 31 09:33:00 Constellation launchd: backup.work: 9 more failures without living at least 60 seconds will cause job removal

I've tried changing the script so it does something minimal:
#!/bin/bash
cd /scratch

and even this returns an exit code of 1!

Permissions:
-rwxr-xr-x 1 root wheel 87 May 31 09:32 backup

( They are User agent, and using Lingon to create the job)

The script runs fine in terminal.

Plist:

<?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>Debug</key>
<true/>
<key>Label</key>
<string>backup.work</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>/usr/local/bin/backup</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>21</integer>
<key>Minute</key>
<integer>5</integer>
</dict>
</dict>
</plist>

Any suggestions would be great!

Thanks

PB G4, Mac OS X (10.4)

Posted on May 31, 2007 6:35 AM

Reply
6 replies

May 31, 2007 10:01 PM in response to Stewart Hector

I'm just asking a dumb question here:

Look at:

<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>/usr/local/bin/backup</string>
</array>


You can actually get away with specifying multiple jobs to run consecutively like this by stacking them in an array? I thought that the ProgramArguments array simply facilitated passing arguments into an executable (that can either be specified in a separate, stand-alone Program key or optionally specified as the first array item in the ProgramArguments key). I didn't think that you could specify a sequence of executables to launch consecutively like you are doing.

Try this:

Create new script:
!# /bin/sh
/usr/local/bin/backup
exit 0


modifiy your plist:
<key>ProgramArguments</key>
<array>
<string>/Full/Path/To/The/Above/Homegrown/Script</string>
</array>

Jun 1, 2007 11:40 AM in response to j.v.

Now that I am more awake (previous post was done late last night), here is a clarification:

What I suggested last night would be appropriate if you were launching multiple scripts with this new homegrown job (I only showed you launching one single job, "backup," there).

If the first line in backup is !# /bin/sh, that should be sufficient to declare the operating environment in which backup is to run. I don't see you needing to run /bin/sh separately before you run the backup script, as you were trying to do in the plist. Plus, I'm not convinced that running /bin/sh before running backup would propagate onward into backup's environment.

For a single job, with !# /bin/sh as the first line in backup, then you should be able to
<string>/usr/local/bin/backup</string>
instead of
<string>/Full/Path/To/The/Above/Homegrown/Script</string>
as I had written earlier.

Jun 2, 2007 2:41 AM in response to Stewart Hector

Hi Stewart,
It's my belief that the error message is actually accurate in the literal interpretation. The error message says nothing about your script's return value. It says that the job returned an error, which allows for the possibility that your script behaved inappropriately even if it did what it was supposed to do successfully. The message even goes on to describe the inappropriate behavior. It says that the script didn't run long enough. Launchd monitors jobs and is programmed to interpret rapid exit as a failure of the script. You can check this by putting the following line in your test script.

sleep 61

You don't indicate what your original script looks like but if it's backing up much, it will probably run more than a minute. You might try making sure that the script doesn't return until the job is completely done.

Launchd doesn't expect to keep the job alive if the property list contains the following key:

<key>OnDemand</key>
<true/>

That is actually supposed to be the default value but that can't be true for all situations because I know of cases in which the key is required. I have no idea if this is one of them but it's a possibility so I feel compelled to mention it.
--
Gary
~~~~
Eating chocolate is like being in love without the aggravation.

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 scheduled job always returns exit code:1

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