Skip to main content
Question

Help with script giving error message when ran through Self Service


Forum|alt.badge.img+14
  • Valued Contributor
  • 342 replies

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...

  1. It executes another policy that installs mysides which is an application I found that lets me automate adding a shortcut to the Finder sidebar.

  2. It mounts a share for the user.

  3. 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

6 replies

chris_kemp
Forum|alt.badge.img+20
  • Jamf Heroes
  • 339 replies
  • February 22, 2016

Try adding a zero to the exit line:

exit 0

apizz
Forum|alt.badge.img+15
  • Honored Contributor
  • 395 replies
  • February 22, 2016

I'd also put quotes around "/Volumes/Home" for your Home_Drive variable


Forum|alt.badge.img+14
  • Author
  • Valued Contributor
  • 342 replies
  • February 22, 2016

@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.


apizz
Forum|alt.badge.img+15
  • Honored Contributor
  • 395 replies
  • February 22, 2016

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"


Forum|alt.badge.img+18
  • Honored Contributor
  • 486 replies
  • February 22, 2016

Speaking of best practices... shellcheck.net


apizz
Forum|alt.badge.img+15
  • Honored Contributor
  • 395 replies
  • February 23, 2016

cool beans @rderewianko like that a lot


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings