So I've been working on a script to map a users home drive, then use a file on there to map the rest of their drives. This is the code for the first part (redacted in some places):
#!/bin/sh
exec >> "/var/log/drive.log" 2>&1 ## must be run as admin or root for exec to work
sudo defaults write /Library/Preferences/com.apple.NetworkAuthorization AllowUnknownServers -bool YES
#Get the logged in users username
loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
#Get logged in users home server
userHomeServer=$(dscl /Active Directory/COMPANY/All Domains -read /Users/$loggedInUser SMBScriptPath | awk '{if(NR>1)print}' | cut -c 14- | cut -c -6 | tr -d '[:space:]')
if [[ $userHomeServer == *"AU"* ]]
then
echo "AU home drive"
userHomeServer=$(dscl /Active Directory/COMPANY/All Domains -read /Users/$loggedInUser SMBScriptPath | awk '{if(NR>1)print}' | cut -c 14- | cut -c -8 | tr -d '[:space:]')
echo $userHomeServer
elif [[ $userHomeServer == *"PHX"* ]]
then
echo "PHX home drive"
userHomeServer=$(dscl /Active Directory/COMPANY/All Domains -read /Users/$loggedInUser SMBScriptPath | awk '{if(NR>1)print}' | cut -c 14- | cut -c -9 | tr -d '[:space:]')
echo $userHomeServer
elif [[ $userHomeServer == *"CH"* ]]
then
echo "CH home drive"
userHomeServer=$(dscl /Active Directory/COMPANY/All Domains -read /Users/$loggedInUser SMBScriptPath | awk '{if(NR>1)print}' | cut -c 14- | cut -c -8 | tr -d '[:space:]')
echo $userHomeServer
else
echo "Normal Home Drive"
userHomeServer=$(dscl /Active Directory/COMPANY/All Domains -read /Users/$loggedInUser SMBScriptPath | awk '{if(NR>1)print}' | cut -c 14- | cut -c -6 | tr -d '[:space:]')
echo $userHomeServer
fi
homeDrive="Mount Volume "smb://COMPANY.com/SERVER/$userHomeServer/$loggedInUser""
echo "Home Drive: $homeDrive"
#Mount the network Drive
osascript -e "$homeDrive"
So it works fine and mounts the home drive. But there area cases when a user isn't logged in or a local admin is logged in. Also sometimes their extra drives file has drives which they don't have access to. So using this method, if there is an error it pops up they default "There was a problem connecting to server".
So was wondering if there is a stealthier method to map a network drive and if there is a failure of any kind, to just report it in the log file and not bother the user.