I know there are a lot of variations on this theme out there but here is a script I have made for mounting shares straight out of Casper without requiring anything on the client machine that might be a fit for someones needs. Primarily I wanted a scripted solution but without a deployment requirement and plus I felt like doing it.
It accepts a single parameter in the form smb://server/share
If it has no parameter it uses the AD home drive of the user
It is designed to be called with the login trigger or a custom trigger
It is designed to be scoped to the appropriate group with access rights to the share
It seperates away from the rest of the policies and continues to run in the background to allow other login processes to continue
It runs invisibily to the user until the drives show on the Desktop
It logs individual share activities to /Library/Logs/Sharemounts/Sharemounts_share.log
As always test and use at your own risk! I have done some testing with 10.10 and 10.9 and with a custom launchDaemon to detect network changes and wake events and it seems to do as required, but we are not using it in production yet.
If anyone has any improvements or feedback let me know.
THERE IS NOW AN UPDATED VERSION FURTHER DOWN THE THREAD
#!/bin/bash
#Mounts the requested share if it doesn't already exist
#Accepts shares in the standard form smb://server/share
#In the event of the share being left blank it will attempt to mount the AD home share
#Start seperate process
(
#Initialise variables
Run_Delay=10
Run_Limit=5
Share_Path=$4
if [ -z "$Share_Path" ]; then
Share_Path="home"
Share_Name="home"
else
Share_Name="$(echo $Share_Path | awk -F"/" '{print $NF}')"
fi
Log_Name=$Share_Name
Current_User=$(stat -f%Su /dev/console)
#Notify start of process
mkdir -p /Library/Logs/Sharemounts
echo "$(date) Sharemount for $Share_Name share started" > /Library/Logs/Sharemounts/Sharemount_"$Log_Name".log
#Loop through attempting to mount share as current user
while [[ -z "$(mount | awk '/'$Current_User'/ && /'$Share_Name'/')" ]] && [[ $Run_Count -lt $Run_Limit ]] ; do
let Run_Count=$Run_Count+1
echo "Sharemount attempt $Run_Count to mount $Share_Name" >> /Library/Logs/Sharemounts/Sharemount_"$Log_Name".log
if [[ "$Current_User" ]] && [[ "$Current_User" != "root" ]] && [[ "$(ps -c -u $Current_User | awk /Finder/)" ]]; then
echo "Sharemount user $Current_User and Finder verified proceeding with mount attempt" >> /Library/Logs/Sharemounts/Sharemount_"$Log_Name".log
if [ "$Share_Path" == "home" ];then
Machine_Domain=$(dscl /Active Directory/ -read . SubNodes | awk '{print $2}')
Share_Path="smb:$(dscl "/Active Directory/$Machine_Domain/All Domains" -read /Users/$Current_User SMBHome | awk '{print $2}' | sed 's/\\///g')"
Share_Name="$(echo $Share_Path | awk -F"/" '{print $NF}')"
fi
echo Sharemount attempting to connect to $Share_Path >> /Library/Logs/Sharemounts/Sharemount_"$Log_Name".log
su -m $Current_User -c /usr/bin/osascript<<END
tell application "Finder"
mount volume "$Share_Path"
end tell
END
sleep 1
else
echo "Sharemount user $Current_User or Finder failure refreshing parameters before next attempt" >> /Library/Logs/Sharemounts/Sharemount_"$Log_Name".log
fi
if [[ -z "$(mount | awk '/'$Current_User'/ && /'$Share_Name' /')" ]]; then
sleep $Run_Delay
Current_User=$(stat -f%Su /dev/console)
fi
done
#Test for and output results
if [[ -z "$(mount | awk '/'$Current_User'/ && /'$Share_Name' /')" ]]; then
echo "$(date) Sharemount for $Share_Name share FAILED" >> /Library/Logs/Sharemounts/Sharemount_"$Log_Name".log
else
echo "$(date) Sharemount for $Share_Name share SUCCEEDED" >> /Library/Logs/Sharemounts/Sharemount_"$Log_Name".log
fi
) &
#End seperate process
