Manually mounting SMB home directory

AdamH
New Contributor II

We have an environment where many people have laptops and almost never connect using a wire. Because of this the mounted SMB home directory falls off and don't get mounted again because its a login script for AD. I'd like to provide the users with a script that would mount their home directory for them.
Does anyone know of a way to manually get the home directory info from AD and mount it?
It would be easy if we had only on server where home directories were located, but we have several, and the only way to know who's is where is to get the path from AD.

thanks!

12 REPLIES 12

jarednichols
Honored Contributor

Here's mine. I run it as a "once per user" policy. It mounts their AD-defined home share and adds it to the Dock for future use. If they're on the wire and get a Kerberos ticket generated it'll mount when they click on it on the Dock. If they're offline and then VPN in (i.e. don't have a Kerberos ticket), they'll be prompted for creds if they click on it to mount it.

#!/bin/sh

# Filename: mountShares.sh
# Purpose: Mount file shares automatically with Kerberos ticket
# Author: Jared F. Nichols

#Find the logged in user
user=`ls -la /dev/console | cut -d " " -f 4`

#Find their P drive server
server=`dscl . -read /Users/$user | grep SMBHome: | cut -d '' -f 3`

#Set this temp string because 'defaults' is literal and won't resolve variables
tmpStr='<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/Volumes/'$user'</string><key>_CFURLStringType</key><integer>0</integer></dict><key>showas</key><integer>2</integer></dict><key>tile-type</key><string>directory-tile</string></dict>'

#Mount the user's P drive
sudo -u $user jamf mount -server $server -share $user -type smb

#Write the P drive to the dock
sudo -u $user defaults write /Users/$user/Library/Preferences/com.apple.dock persistent-others -array-add $tmpStr

#Kick the Dock in the ass. Nothing else to see here, folks.
killall Dock

tlarkin
Honored Contributor

I believe just doing this will output the full path of the SMB home, not able to test, so please test.

dscl . read /Users/username SMBHome

Then just put that into a variable with the mount command, or the JAMF binary.

Hope this helps,
Tom

jarednichols
Honored Contributor

Ah that's a good one. Thanks

tlarkin
Honored Contributor

Or just use Jared's script haha. I did not see Jared replied to this, as I did not hit submit yet on here.

Cheers
tom

jarednichols
Honored Contributor

Your dscl lets me kill the grep though. :)

tlarkin
Honored Contributor

Ironically I just learned this attribute was even there on cached AD accounts. Professionally I haven't had to support a Windows server since 2004ish. I was always the guy that got stuck managing the Macs and Linux boxes. When I found this I was like, this is way easier than parsing XML...derp

:-)

Tom

bentoms
Release Candidate Programs Tester

This is what I do: http://macmule.com/2011/09/08/how-to-map-drives-printers-based-on-ad-group-membership-on-osx/

That way when people drop connection due to whatever, they can re-run the app & get their drives back.

jarednichols
Honored Contributor

Meh, not a fan of AppleScript, but to each his own. If it works for you, cool :)

bentoms
Release Candidate Programs Tester

Yea but if it does the job. :)

Gives the users something to press when they lose connection + runs as the user so uses their Kerberos ticket etc.

(oh & it's mostly bash in AppleScript anyways. :))

jarednichols
Honored Contributor
(oh & it's mostly bash in AppleScript anyways. :))

So do it in Bash ;)

nkalister
Valued Contributor

I do a combo- I have a script that mounts the user directory using a dscl query and a launchagent for automounting at login, and an applescript based GUI app that runs a slightly modified version of the BASH script for people who VPN in and don't have a corporate connection at login.

tlarkin
Honored Contributor
I do a combo- I have a script that mounts the user directory using a dscl query and a launchagent for automounting at login, and an applescript based GUI app that runs a slightly modified version of the BASH script for people who VPN in and don't have a corporate connection at login.

Hey Nick,

If you don't mind sharing with me I'd love to see this. I have got similar projects I am working on. You can send it to me via email if you don't want to post it here. Thanks in advance!

Tom