Login Script for local user not working. Using dockutil and launchd

Osburn
New Contributor II

I've had great sussecces with using dockutil for our network accounts. At our school we have a generic local account named students incase of network outage or other problems. I'm trying to modify the dock of this generic account so that the dock goes back to a set state at each login. I've read I should try and not use loginhooks anymore and instead use a launch agent events.

I've followed the suggestions here http://stackoverflow.com/questions/1370901/very-simple-launchd-plist-not-running-my-script

The script made can be run by the students account and without error

In the logs I get this odd error from launchd

(com.deltaschools.dockutil.app[2944]) Job failed to exec(3) for weird reason: 8
9/23/14 3:46:17.087 PM com.apple.launchd.peruser.600[807]:
9/23/14 3:46:18.116 PM com.apple.launchd.peruser.600[807]: (com.deltaschools.dockutil.plist) Job should be able to exec(3) now.

Here is my JSS script.

#!/bin/bash
THEUSER=students
#user name
SCPFOLDER=/Users/$THEUSER/Library/Scripts
#Dockutil config folder
OCFOLDER="/Users/$THEUSER/Library/LaunchAgents/"


mkdir -p "$SCPFOLDER";
mkdir -p "$OCFOLDER";
# make folders above

sudo chown -R $THEUSER "$SCPFOLDER";
#change to owner to current user

cat > "$SCPFOLDER/studentsdock.sh" <<EOF
 /usr/bin/dockutil --remove all "/Users/students" 
 /usr/bin/dockutil --add "/Applications/Safari.app" "/Users/students" 
 /usr/bin/dockutil --add "/Applications/Firefox.app" "/Users/students" 
 /usr/bin/dockutil --add "/Applications/Google Chrome.app" "/Users/students" 
 /usr/bin/dockutil --add "/Applications/Microsoft Office 2011/Microsoft Word.app" "/Users/students" 
 /usr/bin/dockutil --add "/Applications/Microsoft Office 2011/Microsoft Excel.app" "/Users/students" 
 /usr/bin/dockutil --add "/Applications/Microsoft Office 2011/Microsoft PowerPoint.app" "/Users/students" 
 /usr/bin/dockutil --add "/Applications/Keynote.app" "/Users/students" 
 /usr/bin/dockutil --add "/Applications/Numbers.app" "/Users/students" 
 /usr/bin/dockutil --add "/Applications/Pages.app" "/Users/students" 
 /usr/bin/dockutil --add "/Applications/Calculator.app" "/Users/students" 
 /usr/bin/dockutil --add "/Applications/Calendar.app" "/Users/students" 
 /usr/bin/dockutil --add http://online3.typingmaster.com/login?id=pfn84kh57 --label "TypingMaster Online" 
 /usr/bin/dockutil --add https://cloud.deltaschools.com --label "DCSD Cloud Storage" 
 /usr/bin/dockutil --add /Applications --view list --sort name "/Users/students" 
 /usr/bin/dockutil --add /Users/students/Downloads --view list --sort name "/Users/students" 
 /usr/bin/dockutil --add /Users/students/Documents --view list --sort name "/Users/students" 
EOF
# write script with dockutil settings

cat > "$OCFOLDER/com.deltaschools.dockutill.plist" <<EOF
<?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.deltaschools.dockutil</string>
        <key>Program</key>
        <string>$SCPFOLDER/studentsdock.sh</string>
        <key>RunAtLoad</key>
        <true/>
    </dict>
</plist>
EOF
# write plist to launch studentdock.sh script

chmod a+x "$SCPFOLDER/studentsdock.sh"
#make script run
launchctl load -wF "$OCFOLDER/com.deltaschools.dockutill.plist"
# add plist to launchctl

Files made from running script in casper remote com.deltaschools.dockutill.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.deltaschools.dockutil</string>
        <key>Program</key>
        <string>/Users/students/Library/Scripts/studentsdock.sh</string>
        <key>RunAtLoad</key>
        <true/>
    </dict>
</plist>

studentsdock.sh

/usr/bin/dockutil --remove all "/Users/students" 
 /usr/bin/dockutil --add "/Applications/Safari.app" "/Users/students" 
 /usr/bin/dockutil --add "/Applications/Firefox.app" "/Users/students" 
 /usr/bin/dockutil --add "/Applications/Google Chrome.app" "/Users/students" 
 /usr/bin/dockutil --add "/Applications/Microsoft Office 2011/Microsoft Word.app" "/Users/students" 
 /usr/bin/dockutil --add "/Applications/Microsoft Office 2011/Microsoft Excel.app" "/Users/students" 
 /usr/bin/dockutil --add "/Applications/Microsoft Office 2011/Microsoft PowerPoint.app" "/Users/students" 
 /usr/bin/dockutil --add "/Applications/Keynote.app" "/Users/students" 
 /usr/bin/dockutil --add "/Applications/Numbers.app" "/Users/students" 
 /usr/bin/dockutil --add "/Applications/Pages.app" "/Users/students" 
 /usr/bin/dockutil --add "/Applications/Calculator.app" "/Users/students" 
 /usr/bin/dockutil --add "/Applications/Calendar.app" "/Users/students" 
 /usr/bin/dockutil --add http://online3.typingmaster.com/login?id=pfn84kh57 --label "TypingMaster Online" 
 /usr/bin/dockutil --add https://cloud.deltaschools.com --label "DCSD Cloud Storage" 
 /usr/bin/dockutil --add /Applications --view list --sort name "/Users/students" 
 /usr/bin/dockutil --add /Users/students/Downloads --view list --sort name "/Users/students" 
 /usr/bin/dockutil --add /Users/students/Documents --view list --sort name "/Users/students"
4 REPLIES 4

mm2270
Legendary Contributor III

So, you're creating the LaunchAgent via script? The problem most likely is the permissions aren't being set right on the resulting launchd plist. LaunchAgents and LaunchDaemons are very finicky about permissions and will not run if things are not set just so. Although the error doesn't specifically state that as the issue, try adding the following to your script after the lines where you create the plist.

chown root:wheel /Library/LaunchAgents/com.deltaschools.dockutill.plist
chmod 644 /Library/LaunchAgents/com.deltaschools.dockutill.plist

launchd's need 644 and root:wheel as above. So give that a shot and see if it runs. if not, post back with any updated error information.

Osburn
New Contributor II

Same error sadly

9/24/14 10:09:02.416 AM com.apple.launchd.peruser.600[798]: (com.deltaschools.dockutil[7421]) Job failed to exec(3) for weird reason: 8

ls -l outputs
drwxr-xr-x 3 students 600 102 Sep 23 17:01 Scripts
-rwxr-xr-x@ 1 students 600 1407 Sep 24 10:08 studentsdock.sh

drwxr-xr-x 3 root 600 102 Sep 23 15:21 LaunchAgents
-rw-r--r-- 1 root wheel 375 Sep 24 10:08 com.deltaschools.dockutill.plist

C02N3QSHG086:LaunchAgents students$ launchctl list
PID Status Label

  • 8 com.deltaschools.dockutil

I listed some outputs on the permissions if that helps .

Osburn
New Contributor II

I also tried setting the script to 644 and now the error is

9/24/14 10:42:50.938 AM com.apple.launchd.peruser.600[832]: (com.deltaschools.dockutil[882]) Exited with code: 13

mm2270
Legendary Contributor III

What happens if you manually try loading the LaunchAgent? Also, you might want to consider using an application designed to create launchd's, like LaunchControl! or the older Lingon.
Although its possible to create them manually or from a script, I've found I've had far better luck in allowing an application to create them so the formatting, permissions and everything else is set correctly. As I said, they are quite finicky and won't run if things are even slightly out of order.

Is there a specific need to create it and load it directly from a script, or is it possible to create it and package it up in a pkg deployment? You may have better luck trying it that way.
Anyway, give one of those applications a shot as a first test. If it works after recreating it in one of those apps, then it points to how your script is creating the LaunchAgent.