Posted on 05-07-2014 12:19 PM
Hey all,
I would like to automate the mounting of our Users Windows home directory. If I leave "Use UNC path from Active Directory to derive network home location" checked, it will find the home folder (or at least it seems), place it in the right side of the Dock. Unfortunately the folder is not accessible and has a ? in place of the icon, nor is there a way to remove it. So next step was to uncheck the above option and try to script this.
So in trying to script this, I have come up with this
#!/bin/bash
#This will make the temp directory that is needed to mount the Home Dir
whd=/Users/Shared/tmp/
if [ -d "$whd" ]
then
echo "exists"
sleep 5
else
mkdir $whd
echo "now exists"
fi
#Get the home directory for the logged in user and then mount the users home directory
dscl . read /Users/$3 SMBHome
#Next mount the Home Directory
mount_smbfs -N //fileshare/path/ /Users/Shared/tmp/
my problem now is how to pipe only the result of dscl . read /Users/$3 SMBHome to the //fileshare/path.
Can anyone provide some scripting-fu to help, or if there is a better way to do this?
Thanks in advance.
Posted on 05-07-2014 01:49 PM
I'd instead do something like this:
#Find the logged in user
user=`ls -la /dev/console | cut -d " " -f 4`
#Find their SMBHome server
server=`dscl . -read /Users/$user | grep SMBHome: | cut -d '' -f 3`
#Mount the user's SMBHome
sudo -u $user jamf mount -server $server -share $user -type smb
As always, test test test.
Posted on 05-08-2014 06:28 AM
Ben Toms has a very useful script:
http://macmule.com/2011/09/08/how-to-map-drives-printers-based-on-ad-group-membership-on-osx/
We have a lot of users that rarely reboot their laptop, so I modified his LaunchAgent with some code from the jamf changeNetworkState trigger LaunchAgent so that the AppleScript is run whenever the network state changes.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.mountShares.plist</string>
<key>ProgramArguments</key>
<array>
<string>/Applications/mountDrives.app/Contents/MacOS/applet</string>
</array>
<key>WatchPaths</key>
<array>
<string>/Library/Preferences/SystemConfiguration/preferences.plist</string>
</array>
</dict>
</plist>
In my version of his AppleScript, if the network SSID changes to ours, the shares are mounted. If the network SSID changes to anywhere else, then any mounted shares are ejected.
Posted on 05-08-2014 06:43 AM
Our user home drives are not placed in the SMBHome string in AD (why I can't fathom, everyone says it's just how we've always done it). I had to write a rather tedious Apple Script (with launch agent) to do the mounting based off script from MacMule. I've made some modifications to fit our environment but it works pretty well now.
-------------------------------
--- User Information
-- Get the logged in users username
on theSplit()
try
set fulluser to do shell script "whoami"
set AppleScript's text item delimiters to "\"
set parts to text items of fulluser
set firstitem to the first item of parts
set seconditem to the second item of parts
set slash to "\"
set username to seconditem
on error
set username to do shell script "whoami"
end try
return username
end theSplit
set loggedInUser to theSplit()
-- Get the Users account UniqueID
set accountType to do shell script "dscl . -read /Users/$(whoami) | grep UniqueID | cut -c 11-"
-- Get the nodeName from the Users account
set nodeName to do shell script "dscl . -read /Users/$(whoami) | awk '/^OriginalNodeName:/,/^Password:/' | head -2 | tail -1 | cut -c 2-"
-- Get the Users group membership from AD
set ADGroups to do shell script "dscl " & quoted form of nodeName & " -read /Users/$(whoami) | awk '/^dsAttrTypeNative:memberOf:/,/^dsAttrTypeNative:msExchHomeServerName:/'"
-- Get the Users AD Home Folder
set ADHome to do shell script "dscl " & quoted form of nodeName & " -read /Users/$(whoami) | grep SMBHome: | cut -c 10- | sed 's/\\/\//g' "
After the script gathers the necessary information there are dozens of strings like the following.
if ADGroups contains "Anatomy-Users" then
mount volume "smb://server.domain.forest.edu/" & loggedInUser & "$"
mount volume "smb://server.domain.forest.edu/Anatomy"
end if
if ADGroups contains "Anatomy-Davissonlab" then
mount volume "smb://server.domain.forest.edu/DavissonLab"
end if
Posted on 05-08-2014 09:01 PM
This works for us just fine. We packaged it up into an Automator app that can be installed from Self Service, so the users can mount their drive whenever they want.
HOMEFOLDER=$( dscl "/Active Directory/YOURDOMAIN/All Domains" -read /Users/$USER dsAttrTypeNative:homeDirectory | awk '{print $2}' ) mount -t smbfs $HOMEFOLDER /Users/Shared/HomeFolder
Posted on 05-09-2014 01:49 PM
Thanks for all the responses. I will try these out. JamfNation Community to the rescue!
Posted on 05-13-2014 01:11 PM
@jarednichols I tried this out, but I get a
"There was an error mounting the file server. Will attempt again.
Mounting to /Volumes/share...
There was an error mounting the file server . Giving up." error.
I tried mount_smbfs //fileshare/path /Users/Shared/temp and I got "mount_smbfs: server rejected the connection: Authentication error"
Is there a way to pass your currently logged on credentials to either of these methods?
Posted on 10-25-2014 01:54 PM
@jrserapio, if you look at the link to my blog that @lwindram posted, the app is run as the user & so uses their kerberos ticket to mount the shares.. dumbing down the process somewhat.
Posted on 08-15-2017 01:55 PM
Hello @jrserapio did you ever figure out the mounting of the fileshare above? We are seeing the same error when trying to get this to work. Perhaps you found a way to get this up and running. When I comment out the line about mounting, no error. We can perhaps train our users to click on the globe icon in the dock, but it would be great to have this happen automatically.
Thanks...
Posted on 08-15-2017 02:10 PM
Hello @jarednichols and thank you for your quick script idea above from years ago. I attempted to use it and everything is working EXCEPT the auto mounting of it. Do you have any other methods you use to automatically mount the logged in user's home folder? Any ideas Jared would be most welcome...thank you.