Posted on 02-20-2017 08:25 AM
Wanting to create an Auto Mount Policy for SMB Share based on the current user who logs in. This would allow any user to access there SMB shared docs at any computer.
How do i pass through the current user to this?
smb://$currentUser@{ServerName}/$currentUser/Docs
Posted on 02-20-2017 08:30 AM
Current user can be found like this:
currentUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }')
You might have trouble passing passwords though.
Regards,
TJ
Posted on 02-20-2017 08:32 AM
Thanks @tthurman ! Not worried about passwords. Want the user to have to enter that themselves.
Ben
Posted on 02-20-2017 08:53 AM
Many of us have switched to using the following for finding the current logged in user. This code supposedly came from someone at Apple at some point.
loggedInUser=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");'`
Posted on 02-20-2017 11:28 AM
What is the best process for doing this? Script in JAMF, if so what have does yours look like? Or are others doing it another way?
Posted on 02-20-2017 11:35 AM
What I did, because I found it to be annoying if a user wasn't on the network getting an error on login.
I followed Mac Mule's guide and created an application to mount the drives. I then just made this available in Self Service and let the users run as needed.
Some have it as a launch agent instead, but I didn't like that way personally.
Posted on 02-20-2017 11:40 AM
@Pacers31Colts18 You wouldn't happen to have a link to that article would you?
Ben
Posted on 02-20-2017 11:44 AM
We don't auto mount, but we do use dockutil scripts to create SMB links in the dock for users. This works pretty well for our use.
Posted on 02-20-2017 11:49 AM
https://macmule.com/2011/09/08/how-to-map-drives-printers-based-on-ad-group-membership-on-osx/
Posted on 02-20-2017 12:09 PM
We don't have an AD. I am trying to fake this script to choose the current logged in user...
So for example:
smb://$currentUser@{ServerName}/$currentUser/Docs
I need $currentUser to auto populate per the user logged in.
I am having no luck with this so far. It simple to accomplish by typing in the user but I want to be able to pass this to everyone per login.
Posted on 02-20-2017 12:13 PM
We've been getting beat over the head by our UNIX team to stop using backticks...
So this:
loggedInUser=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");'`
Should be:
loggedInUser=$( python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");' )
http://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xcu_chap02.html#tag_23_02_06_03
Posted on 02-20-2017 12:40 PM
@cbrewer "We don't auto mount, but we do use dockutil scripts to create SMB links in the dock for users. This works pretty well for our use."
could you provide your work-flow (scripts/steps) on how you are utilizing SMB links on the dock (using dockutil).
Thank you.
Posted on 02-20-2017 02:05 PM
We disable auto mount on login to speed up login times, so I created an AppleScript app that the user is able to click on to mount a network drive. The app is located in the /Library/Application Support folder (but can be placed anywhere) and the icon is placed in the dock using dockutil.
The script looks something like this:
set userName to do shell script "whoami"
set mountString to "smb://network.share/home/" & userName
try
if (list disks) does not contain userName then
mount volume mountString
delay 3 -- wait for the volume to mount or Finder will fail to open
tell application "Finder"
activate
open disk userName
end tell
else
tell application "Finder"
activate
open disk userName
end tell
end if
end try
We push out the app via a policy to all computers, which also includes the dockutil script to add it to the users dock.
Hope this helps!
Posted on 02-20-2017 02:16 PM
@osxadmin Here's a piece of one of my scripts. memberOf finds AD groups that the user belongs to. OthersList is basically a list of what's already in the dock so we don't add a duplicate. The script then only makes additions to the dock if the conditions are right.
#!/bin/bash
#variables
user=$3
memberOf=`id -G -n $3 | tr '[:upper:]' '[:lower:]'`
OthersList=`defaults read /Users/$user/Library/Preferences/com.apple.dock persistent-others | grep "label"`
server="myserver.domain"
if [[ $memberOf =~ "test group" ]];then
if [[ ! $OthersList =~ "Test Share" ]];then
/usr/local/bin/dockutil --add smb://$server/share/test --label 'Test Share' --position end --no-restart /Users/$user
echo "Added Test Share"
fi
fi
Posted on 02-20-2017 03:13 PM
@cbrewer Thank you very much!