mount network share on user desktop script

EliasG
Contributor

I have tried a few different scripts to mount a network share on user desktop, When I run it inside terminal it works. When i use the script in casper it does not. Has anyone had any luck with this.
#!/bin/bash

mkdir /Users/$USER/Desktop/mnt

mount -t smbfs //nas03.elnet.eastlongmeadow.org/Documents/School/MountainView/Shared%20Folder /Users/$USER/Desktop/mnt

1 REPLY 1

mm2270
Legendary Contributor III

Most of the time these kinds of scripts need to be run as the user. When you run it in Terminal while logged in its being run as that user. When run from a Casper Suite policy its running as root.

In your script you're using the built in $USER variable which will end up being the root account or your Casper service account and not the logged in user. I wouldn't recommend using that. Get the logged in user name with something else like

loggedInUser=$( ls -l /dev/console | awk '{print $3}' )

Use that in place of $USER in the above script.
Later in the script, you might need to also run the mount command as that user. You can try this:

sudo -iu "${loggedInUser}" mount -t smbfs //nas03.elnet.eastlongmeadow.org/Documents/School/MountainView/Shared%20Folder /Users/$loggedInUser/Desktop/mnt

It may or may not work. There are other options if that doesn't do it.