Posted on 02-22-2016 02:48 PM
Any chance someone can explain to me why this gives me an error code of 1 on the lines that executes mysides towards the end? I won't proclaim to be the greatest scripter around so if you want to offer suggestions, I'm all ears.
Basically what this script does is a few things...
It executes another policy that installs mysides which is an application I found that lets me automate adding a shortcut to the Finder sidebar.
It mounts a share for the user.
Lastly, now is when it creates the shortcut I mentioned above. On this line is where I get the error. It still does what it is suppose to do so I can't figure out why I'm getting the error message.
This is being run out of Self Service so I get an error message telling me that it cannot install item. Like I said though it is doing what it's suppose to do and if I run it manually in a shell, it works fine without an error. I can't help but think it's a Self Service bug at this point but thought I would ask the experts here because frankly I don't consider myself one when it comes to scripting. Thanks!
#!/bin/sh
Current_User=$(stat -f%Su /dev/console)
Home_Drive=/Volumes/Home
Current_Domain_Group="FakeDomainDomain Users"
Share_Path="smb://fakeserver.fakeserver.com/home2$/$Current_User"
sudo jamf policy -event addHomeDriveFinderToSidebar
mkdir $Home_Drive
chown $Current_User:"$Current_Domain_Group" $Home_Drive
sudo -u $Current_User mount -t smbfs $Share_Path /Volumes/Home
sudo -u $Current_User /usr/local/bin/mysides add $Current_User file://$Home_Drive
exit
Posted on 02-22-2016 02:53 PM
Try adding a zero to the exit line:
exit 0
Posted on 02-22-2016 02:55 PM
I'd also put quotes around "/Volumes/Home" for your Home_Drive variable
Posted on 02-22-2016 02:59 PM
@chris.kemp I gave that a try. The first time I ran it, it crashed Self Service but the second and third times have ran perfectly. I'm not sure what to think about that one.
@aporlebeke Thanks! The current method seems to be working fine but I'll make the change if that's considered best scripting practices.
Posted on 02-22-2016 03:05 PM
If you're setting the output of a command as a variable you can use $( command ) or command
For setting a particular string to a variable you definitely want to use quotes like you do for your 3rd variable - "stringy string"
Posted on 02-22-2016 03:18 PM
Speaking of best practices... shellcheck.net
Posted on 02-22-2016 07:14 PM
cool beans @rderewianko like that a lot