Skip to main content

Hi,



I wrote this simple script to mount out network drives. I got it to allow the user to mount to the finder but, then they have to drag their folder over to the desktop. Is there any way I can have the script check who is logged in and then mount their folder to their desktop?



Thanks,
Jared

check out :



https://jamfnation.jamfsoftware.com/discussion.html?id=14262#responseChild86562



@davidacland script is what I use and it works fine



I do add a few lines though to grab current logged in user and make sure drive is mounted on desktop



#!/bin/bash

theuser=$(/usr/bin/who | awk '/console/{ print $1 }')
/usr/bin/osascript > /dev/null << EOT

tell application "Finder"
activate
mount volume "smb://zfssa1/home_staff/${theuser}/"
end tell


EOT

echo $theuser
killall cfprefsd
defaults write com.apple.finder ShowMountedServersOnDesktop true
killall -HUP Finder

@BOBW Thank you very much. It worked perfectly.


@BOBW that works, but it asked for a password and pre-fills the users "name" not their AD username.



Is there any way for the script to authenticate based on who's logged in?


@McKinnonTech
yeah, im not 100% sure how to get the current AD user account, we work with local accounts therefore getting the use with above method works fine, maybe using dscl could get it for you.
There is also a script somewhere in JAMF Nation to use kerberos as authentication.



I will try to find them and let you know


You can use this command to mount the user's network drive:



sudo -u $3 /usr/local/jamf/bin/jamf mount -server SERVER.COMPANY.DOMAIN -share "SHARENAME" -type smb -visible



$3 is the variable user is stored in at login



if you're mounting an afp the type would be afp rather than smb.


@McKinnonTech That is the same issue we are running into. We have out server set to scope a folder for each person who logins with their credentials. The issue. . . terminal opens and I added a command to close it but, it won't work because it attempts to close before the script was ran. I wish it could pull the users login credentials and auto mount.


@jared_f I ended up using a script written by @Look over here (the second most recent on in the post):
https://jamfnation.jamfsoftware.com/discussion.html?id=15108



I'm running 10.11.16 and mounting a Synology SMB share, which creates/maps users home drives for you.



Maybe give that script in the post above a go with your set up.


@McKinnonTech I will take a look. Thanks!