Wednesday, September 14, 2011

Mapping Samba Share on OSX

Reference: http://www.mac-forums.com/forums/os-x-operating-system/85454-login-script-mount-smb-drive-desktop.html#post532690

The new Lion 10.7.1 seems to have an issue with reconnection with saved credentials to a Samba share. It wants to try as the logged in user's name and not the saved credential username. Here is one workaround. Create a text file in the users /Users/username directory and call it 'smbmount.command'. Put the following in it (modifying the appropriate variables).


#!/bin/sh

# Put Samba Host IP as Host
host="netbios_name-or-ip_address"

# Desktop Path with trailing slash
desktop="/Users/user/Desktop/"

# Share Username
username="username"

# Share Password
password="password"

# Share 1 Name
shr1="Share1Name"

# Share 2 Name
shr2="Share2Name"



# ---- Don't edit below ---

# Share 1
dir1=${desktop}${shr1}
if [ ! -d "$dir1" ]; then
# Can't Find Directory So Create It
echo "Creating Mount Point: $dir1";
mkdir "$dir1"
else
echo "Found Mount Point: $dir1"
fi
if [ -d "$dir1" ]; then
echo "Mounting..."
mount_smbfs //"$username":"$password"@"$host"/"$shr1" "$dir1"
fi

# Share 2
dir2=${desktop}${shr2}
if [ ! -d "$dir2" ]; then
# Can't Find Directory So Create It
echo "Creating Mount Point: $dir2";
mkdir "$dir2"
else
echo "Found Mount Point: $dir2"
fi
if [ -d "$dir1" ]; then
echo "Mounting..."
mount_smbfs //"$username":"$password"@"$host"/"$shr2" "$dir2"
fi

# NOTE: If you have other Shell Scripts, or the Teriminal.app is running
# enabling the next line will cause the entire Terminal.app to close.
# If you are sure that you can kill the Terminal process feel free to
# uncomment the following line so that the Terminal window the script brings
# up will automatically close when finished

KillAll Terminal


Open a Terminal and chmod a+x the script so that it is executable and then place it in the Login items box so that it auto-starts at login. After that use the Finder, go to Desktop and using the share folders that were created, drag them to the Favorites area for easy access.

No comments:

Post a Comment