error's running script through Launchd

Hi,

I have been trying to get launchd to run a very simple shell script on startup, but the console keeps showing a “Job failed to exec(3) for weird reason” next to the .plist - I added the path to the script to $PATH and made it executable. The script works fine manually. – (The script is merely hiding my PC Google Drive folder “hideGoogleDrive.sh” as shown here:

#! /bin/bash


chflags nohidden /Volumes/PCDrive/Google\ Drive


___


Here is my .plist generated through Lingon X and saved in my /Library/LaunchAgents:


<?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>KeepAlive</key>

<dict>

<key>SuccessfulExit</key>

<false/>

</dict>

<key>Label</key>

<string>com.hideGDrive</string>

<key>ProgramArguments</key>

<array>

<string>/usr/bin/hideGoogleDrive</string>

</array>

<key>RunAtLoad</key>

<true/>

<key>StartOnMount</key>

<true/>

</dict>

</plist>


Any ideas? Thanks in advance.

Kevin

MacBook Pro with Retina display, OS X Mavericks (10.9)

Posted on Dec 15, 2013 7:33 AM

Reply
16 replies

Dec 15, 2013 9:32 AM in response to Barney-15E

This is what I am getting. (btw I now have three .plist's going with variations to see what might take (hidePcGoogleDriveFolder_Dresden.plist, com.hideGFolder.plist, com.hideGDrive -2 of which were written out of Lingon X. I am getting code: 127 which means it can not find the script, but I added the path to $PATH and echo'ed it to see that the path was added, and if I run the command by itself without the explicit path in a different directory, the script will be found and run. Here is the barf:




12/15/13 9:23:00.248 AM com.apple.launchd.peruser.501[174]: (com.hideGDrive[12430]) Exited with code: 127

12/15/13 9:23:00.248 AM com.apple.launchd.peruser.501[174]: (com.hideGDrive) Throttling respawn: Will start in 10 seconds

12/15/13 9:23:10.118 AM com.apple.launchd.peruser.501[174]: (hidePCGoogleDriveFolder_Dresden.plist[12434]) Job failed to exec(3). Setting up event to tell us when to try again: 2: No such file or directory

12/15/13 9:23:10.118 AM com.apple.launchd.peruser.501[174]: (hidePCGoogleDriveFolder_Dresden.plist[12434]) Job failed to exec(3) for weird reason: 2

12/15/13 9:23:10.119 AM com.apple.launchd.peruser.501[174]: (hidePCGoogleDriveFolder_Dresden.plist) Job should be able to exec(3) now.

12/15/13 9:23:10.119 AM com.apple.launchd.peruser.501[174]: (hidePCGoogleDriveFolder_Dresden.plist) Throttling respawn: Will start in 10 seconds

12/15/13 9:23:10.253 AM com.apple.launchd.peruser.501[174]: (com.hideGFolder.plist[12435]) Exited with code: 127

12/15/13 9:23:10.253 AM com.apple.launchd.peruser.501[174]: (com.hideGFolder.plist) Throttling respawn: Will start in 10 seconds

12/15/13 9:23:10.319 AM com.apple.launchd.peruser.501[174]: (com.hideGDrive[12439]) Exited with code: 127

12/15/13 9:23:10.319 AM com.apple.launchd.peruser.501[174]: (com.hideGDrive) Throttling respawn: Will start in 10 seconds

12/15/13 9:23:14.749 AM com.apple.launchd.peruser.501[174]: (hidePCGoogleDriveFolder_Dresden.plist) Throttling respawn: Will start in 6 seconds

12/15/13 9:23:20.258 AM com.apple.launchd.peruser.501[174]: (com.hideGFolder.plist[12443]) Exited with code: 127

12/15/13 9:23:20.258 AM com.apple.launchd.peruser.501[174]: (com.hideGFolder.plist) Throttling respawn: Will start in 10 seconds

12/15/13 9:23:20.325 AM com.apple.launchd.peruser.501[174]: (com.hideGDrive[12447]) Exited with code: 127

12/15/13 9:23:20.325 AM com.apple.launchd.peruser.501[174]: (com.hideGDrive) Throttling respawn: Will start in 10 seconds

12/15/13 9:23:20.750 AM com.apple.launchd.peruser.501[174]: (hidePCGoogleDriveFolder_Dresden.plist[12451]) Job failed to exec(3). Setting up event to tell us when to try again: 2: No such file or directory

12/15/13 9:23:20.750 AM com.apple.launchd.peruser.501[174]: (hidePCGoogleDriveFolder_Dresden.plist[12451]) Job failed to exec(3) for weird reason: 2

12/15/13 9:23:20.750 AM com.apple.launchd.peruser.501[174]: (hidePCGoogleDriveFolder_Dresden.plist) Job should be able to exec(3) now.

12/15/13 9:23:20.750 AM com.apple.launchd.peruser.501[174]: (hidePCGoogleDriveFolder_Dresden.plist) Throttling respawn: Will start in 10 seconds

Dec 15, 2013 11:02 AM in response to ChompyPage

Are you absolutely sure that the file is named "hideGoogleDrive" without the ".sh"? Note that the Finder will often hide extensions. Also, are you sure it's in /usr/bin? (Honestly, I'd put it somewhere in your user folder insted of in /usr/bin.) And are you sure that you have given it execute permissions?


In the Terminal, enter the following command:


ls -al /usr/bin/ | grep hide*


What is the output?

Dec 16, 2013 2:24 AM in response to Linc Davis

I added the .sh extension and am still getting errors. -It's bizzare -the script runs and I have the path added to $PATH - I added /bin/sh to the .plist even:


<key>ProgramArguments</key>

<array>

<string>/bin/sh</string>

<string>/usr/bin/hideGoogleDrive.sh</string>

</array>

<key>RunAtLoad</key>

<true/>


I am getting this error out of the com:

12/16/13 2:14:10.625 AM com.apple.launchd.peruser.501[170]: (com.hidePCGoogleDriveFolderLocal.plist[670]) Exited with code: 127

12/16/13 2:14:10.625 AM com.apple.launchd.peruser.501[170]: (com.hidePCGoogleDriveFolderLocal.plist) Throttling respawn: Will start in 10 seconds


My script is a simple:

#! /bin/bash


chflags nohidden /Volumes/PCDrive/Google\ Drive


Has anyone gotten a .sh script running on startup on a mac- using launchd?


Here is my current .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>Debug</key>

<false/>

<key>Disabled</key>

<false/>

<key>KeepAlive</key>

<dict>

<key>SuccessfulExit</key>

<false/>

</dict>

<key>Label</key>

<string>com.hidePCGoogleDriveFolderLocal.plist</string>

<key>LaunchOnlyOnce</key>

<false/>

<key>ProgramArguments</key>

<array>

<string>/bin/sh</string>

<string>/usr/bin/hideGoogleDrive.sh</string>

</array>

<key>RunAtLoad</key>

<true/>

<key>StartOnMount</key>

<true/>

</dict>

</plist>


@Linc Davis - Yea, if you have a .plist I would like to compare. - Does this particular type of .plist need to be in /Library/LaunchDaemons? not LaunchAgents?

Dec 16, 2013 2:58 AM in response to ChompyPage

Has anyone gotten a .sh script running on startup on a mac- using launchd?


Yes, I've got a custom LaunchAgent running on my machine. In my case, I have put it in my user LaunchAgents folder (~/Library/LaunchAgents) rather than one of the root-level folders. Mine behaves differently from yours, in that it runs at a specific time every night, but here's what it looks like:


<?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.**********.calendarbackup</string>

<key>ProgramArguments</key>

<array>

<string>/Users/thomas/Shell/calbackup.sh</string>

</array>

<key>StartCalendarInterval</key>

<dict>

<key>Minute</key>

<integer>00</integer>

<key>Hour</key>

<integer>20</integer>

</dict>

</dict>

</plist>


This works quite well.


Note that I did not need to modify $PATH, and you do not need to have /bin/sh in the .plist file.

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.

error's running script through Launchd

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