Posted on 06-20-2017 05:38 AM
Hi there,
I'm sure this will be pretty straight forward but was hoping someone could help troubleshoot why this isn't running
I have a basic script set up to add a server into the "Connect to Servers" list
/usr/bin/sfltool add-item -n "OSAKA" com.apple.LSSharedFileList.FavoriteServers "cifs://OSAKA"
killall Terminal
This works a treat when I make it a unix executable, but when I try and make it into a .sh and deploy through Casper scripts I receive the following error:
Sending Wake On LAN command...
Opening SSH Connection to 10.10.32.56...
Authenticating...
Successfully authenticated.
Verifying Computer’s Identity...
The MAC Address has been verified.
Checking Operating System Version...
Running Mac OS X 10.11.6 (15G1510)
Verifying /usr/local/jamf/bin/jamf...
Verifying /usr/sbin/jamf...
/usr/sbin/jamf does not exist.
Downloading /usr/local/jamf/bin/jamf from JSS...
Moving jamf binary to /usr/local/jamf/bin/jamf...
Created the jamf binary directory /usr/local/jamf/bin.
Moving jamf binary to /usr/local/jamf/bin/jamf...
Moved the JAMF CLI Binary to /usr/local/jamf/bin/jamf.
Creating symlink /usr/local/bin/jamf...
Enabling /usr/local/jamf/bin/jamf...
Enabled the JAMF CLI Binary.
Verifying /Library/Preferences/com.jamfsoftware.jamf.plist...
Preparing Policy...
Executing Policy 2017-06-19 at 7:28 PM | brett | 1 Computer
Running script OSAKAmatt.sh...
Script exit code: 1
Script result: Created item with URL: cifs://OSAKA in list:No matching processes were found
Error running script: return code was 1.
Submitting log to https://herschel.jamfcloud.com/
Finished.
Can anyone suggest what I might do to resolve this issue?
Posted on 06-20-2017 06:18 AM
The problem is you aren't specifying the path to the plist you want to effect, which means it's trying to write that value into the root account's preferences. Since root is not logged in, it fails.
You either have to adjust the command to direct it at the full plist path for the current logged in user, or the entire command needs to be run as the logged in user.
The reason it works when you do it in Terminal is because it understands that you are running the command and knows where to locate your com.apple.LSSharedFileList.FavoriteServers
plist or settings.
Also, I'm not sure what the killall Terminal is doing in there. Are you sure the Terminal needs to be quit after this command is run? Somehow I don't think that's necessary.
As you're using the sfltool
in your command, I'm actually not sure if it accepts a full plist path as an argument, so you might have to try running the entire command as the user.
You could try something like the following
#!/bin/bash
loggedInUser=$(stat -f%Su /dev/console)
su $loggedInUser -c "/usr/bin/sfltool add-item -n "OSAKA" com.apple.LSSharedFileList.FavoriteServers "cifs://OSAKA""
Again, not exactly sure what the killall Terminal is there for, so I left it out of the above. Hope that helps.
Posted on 06-20-2017 10:04 AM
Hi @mm2270
Thanks for the response!
The terminal window was still showing on the desktop, I wasn't sure as to the best way for this to run silently.
We are working on a File Server Migration project so want to remove any existing (soon to be erroneous) servers in the list, and simply have 1 entry for the new correct file server in the list. Do you think trying a copy & replace method would be easier / better?
Here's the original script I was working on, which I also managed to get working when specifying the full path, but I'm unsure how to tell this script to copy through to the current user. At this point I think my colleague wants to perform a run-once script after the file server migration so the Connect-To-Servers list clears, then adds the correct entry. From here he has Casper setup to correctly map their network drives to Login Items based on AD groups.
My attempt at "Copy and Paste" plist file below:
#!/bin/bash
" Map the network drive called "Public" to the users computer, where the favourite servers plist file is stored
mount -t smbfs //OSAKA/Public ./Public
" Copy the favourite servers plist file from PUBLIC drive to local computer
cp ./Public/IT/Users/com.apple.LSSharedFileList.FavoriteServers.sfls /Users/Shared
" Once copied to computer, then copy it to all users correct location
cp /Users/Shared/com.apple.LSSharedFileList.FavoriteServers.sfls /Users/matt/Library/Application Support/com.apple.sharedfilelist
" disconnect the network drive, as the file is copied & no longer required
umount ./Public
" Force the Finder application / process to be killed (and reloaded) for teh changes to appear in the Connect to Server window
killall Finder
" If the terminal / script window is still running, close it all this stuff runs silently..
exit
Any feedback on this would be greatly appreciated :)