Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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>
share|improve this answer
    
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 Jun 27 '13 at 2:54
    
Got it to work had to make a folder just for the zip with write permission for everyone. –  ian Jun 27 '13 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 Jun 27 '13 at 16:38
    
Thanks. I turned on debugging for launchd and finally figured it out. –  ian Jun 27 '13 at 20:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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