0

I am trying to run a job with launchd which runs a shell script that creates a zip file I then backup.

I am receiving the error: 6/26/13 5:04:37.992 PM com.apple.launchd.peruser.501[162]: (com.ian.evernote[18163]) Exited with code: 1

Here is my launchd plist:

<?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.ian.evernote</string>
    <key>KeepAlive</key>
    <dict>
        <key>SuccessfulExit</key>
        <false/>
    </dict>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/user/Dropbox/evernote.sh</string>
    </array>
    <key>StartInterval</key>
    <integer>3600</integer>

    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

Here is my shell script:

#!/bin/bash

sudo zip -r ~/Documents/evernote_backup /Users/user/Library/Containers/com.evernote.Evernote/Data/Library

The shell script runs fine from the terminal. What am I doing wrong?

1 Answer 1

1

You cannot execute sudo inside the script. Who's going to enter the password? Why do you need this in the first place? It looks like you are operating inside your home folder where you should have all the permissions you want.

There are two solutions.

  • You need elevated privileges

Make this job a launch daemon instead of an agent. Make sure you change the paths to absolute ones (~ will expand to the executing users home directory, which is / for launch daemons).

  • You're fine with standard privileges

Don't use sudo.

Also: As the script consists of a single line I'd suggest to drop the script and call zip directly:

<key>ProgramArguments</key>
<array>
    <string>/usr/bin/zip</string>
    <string>-r</string>
    <string>/Users/user/Documents/evernote_backup</string>
    <string>/Users/user/Library/Containers/com.evernote.Evernote/Data/Library</string>
</array>
4
  • I have sudo in the script because it doesn't zip without it. zip I/O error: Permission denied zip error: Could not create output file (/Users/user/Documents/evernote_backup.zip) I tried your suggestion of calling it directly but now I get exited with code 15 where do I find out what these codes mean? Is there a reason for the ending line of <string>/usr/bin/zip</string> ? I also set the privileges on the .sh file to x for everyone so I dont know why I needed sudo at all.
    – ian
    Commented Jun 27, 2013 at 2:54
  • Got it to work had to make a folder just for the zip with write permission for everyone.
    – ian
    Commented Jun 27, 2013 at 3:23
  • I removed the last <string>/usr/bin/zip</string> line in the array. The pleasures of copy&paste. As for the error codes: they are usually documented in the man pages. Try man zip and you'll find: 15: zip was unable to create a file to write to
    – LCC
    Commented Jun 27, 2013 at 16:38
  • Thanks. I turned on debugging for launchd and finally figured it out.
    – ian
    Commented Jun 27, 2013 at 20:18

You must log in to answer this question.

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