Posted on 12-28-2021 01:06 PM
Hello,
The organization that I work for maps local samba shares to macs at login when on campus. We use the following script (which has worked flawlessly for years). Unfortunately when running from login hook, the username field now fills with "root" everytime, and the user has to re-input their username to map to the drive. Any ideas on how to fix this?
username="$3"
if [ -z "$username" ]; then # Checks if the variable is empty (user running script from Self Service)
username="$USER"
fi
echo "User: $username"
# Mount the drive
mount_script=`/usr/bin/osascript > /dev/null << EOT
delay 10
tell application "Finder"
mount volume "smb://[SERVERIP]/[Drive]/$username/Documents"
end tell
EOT`
exit 0
Solved! Go to Solution.
12-28-2021 05:51 PM - edited 12-29-2021 05:54 AM
@echalupka Our HomeDrive is named My Documents below is a sanitized version of my script. Hope this helps.
#! /bin/sh
current_User=$(/usr/bin/stat -f%Su /dev/console)
homeDrive_Path="smb://[SERVER]/[PERSONAL_SHARE]/$current_User/My Documents"
homeDrive_Name="My Documents"
sudo -u "${current_User}" osascript <<EOT
on listMountedDisks()
list disks
end listMountedDisks
if (listMountedDisks() does not contain "${homeDrive_Name}") then
mount volume "${homeDrive_Path}"
end if
EOT
Posted on 12-28-2021 01:45 PM
It could be down to server updates. If the smb share is on a Windows Server, older smb protocols like smb 1 have been deprecated due to no enryption. I had issues with smb print shares and had to switch to lpd. I don't use smb drive shares anymore, so not seen this issue myself.
Posted on 12-28-2021 04:30 PM
thanks - hoping that isn't the culprit, although we did just run into that same SMB error with SMB print shares and had to update to lpd in that scenario.
Posted on 12-28-2021 03:03 PM
For good measure i always use the following when the script needs to be run in the user context or reflect data related to the user. I've had issues with $3 parameter in the past and using the following has never failed me.
currentUser=$(stat -f "%Su" /dev/console)
Cheers!
12-28-2021 04:27 PM - edited 12-28-2021 04:29 PM
Thanks @mrheathjones -- forgive my naivety; would this be the correct update to the script?
username="$(stat -f"%Su" /dev/console)"
# Mount the drive
mount_script=`/usr/bin/osascript > /dev/null << EOT
delay 10
tell application "Finder"
mount volume "smb://[SERVERIP]/[Drive]/$username/Documents"
end tell
EOT`
exit 0
12-28-2021 05:51 PM - edited 12-29-2021 05:54 AM
@echalupka Our HomeDrive is named My Documents below is a sanitized version of my script. Hope this helps.
#! /bin/sh
current_User=$(/usr/bin/stat -f%Su /dev/console)
homeDrive_Path="smb://[SERVER]/[PERSONAL_SHARE]/$current_User/My Documents"
homeDrive_Name="My Documents"
sudo -u "${current_User}" osascript <<EOT
on listMountedDisks()
list disks
end listMountedDisks
if (listMountedDisks() does not contain "${homeDrive_Name}") then
mount volume "${homeDrive_Path}"
end if
EOT
Posted on 12-29-2021 08:47 AM
Thanks @mrheathjones -- Updated with the info you provided and we're back up and running!
Eric