3

I'm trying to schedule a simple task in OS X Mountain Lion 10.8.3

launchctl start nextstopsun.helloworld

command doesn't execute the script and throws a message to a console

4/2/13 9:50:49.663 PM com.apple.launchd.peruser.501[139]: (nextstopsun.helloworld[46729]) Job failed to exec(3) for weird reason: 8

My plist is very simple:

<?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>nextstopsun.helloworld</string>
    <key>Program</key>
    <string>/Users/nextstopsun/Work/scripts/hw.sh</string>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>21</integer>
        <key>Minute</key>
        <integer>15</integer>
    </dict>
    <key>UserName</key>
    <string>nextstopsun</string>
</dict>
</plist>

The script is also very simple

echo "Hello World!" > hw.log

launchctl loaded it with no errors. When executing script from shell it works as expected. Logging off and logging back in doesn't help. Didn't find any answer in Google. Whats that "weird reason: 8" all about?

nextstopsun
  • 443
  • 7
  • 14

1 Answers1

8

Few suggestions:

  1. Make your script executable (chmod +x <your_script>) or launch it via bash or sh passing script as parameter
  2. Most likely: You have error in your shebang line (#!) which cant be recognised by launchd. Try #!/bin/sh or #!/bin/bash. Note that it must be the first line in script.
  3. Load your job first via launchctl load <your_plist>. But I think you've already done this or there will be other error message.
cody
  • 3,233
  • 1
  • 22
  • 25
  • 1
    Error 8 is [ENOEXEC "Exec format error"](https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man2/intro.2.html), so it's almost certainly your point 2, broken shebang line. – Ken Thomases Apr 03 '13 at 08:56
  • Agreed, in first case error would be probably EACCES "Permission denied" (13) – cody Apr 03 '13 at 09:00
  • Thanks, I've added shebang line to my script. But now it just says `4/3/13 8:43:39.606 PM com.apple.launchd.peruser.501[139]: (nextstopsun.helloworld[47898]) Exited with code: 1` – nextstopsun Apr 03 '13 at 16:45
  • I had a similar issue today with the JXplorer LDAP client. @cody's first suggestion was dead-on: the app launches via shell script, and the script within the app bundle lacked executable permissions. – Blackcoat May 16 '13 at 18:56