Map Network Drive

armentrout
New Contributor II

I'm running into an interesting issue in getting network drives mapped. At the university I work at we're using each individuals SID to map their network drives so:

storage/homes/SID

I've modified the below script for our environment,

!/bin/bash

Author: Stephen Bygrave - Moof IT

Name: shareConnect.sh

Purpose: Mounts a share on login

Usage: Script in Jamf Pro policy

Version 1.0.0, 2018-04-17

Initial Creation

Use at your own risk. moof IT will accept no responsibility for loss or damage

caused by this script.

Set variables

logProcess="shareConnect"
userName="${3}"
protocol="${4}"
serverName="${5}"
shareName="${6}"

Declare functions

writelog ()
{ /usr/bin/logger -is -t "${logProcess}" "${1}" if [[ -e "/var/log/jamf.log" ]]; then /bin/echo "$(date +"%a %b %d %T") $(hostname -f | awk -F "." '{print $1}') jamf[${logProcess}]: ${1}" >> "/var/log/jamf.log" fi
}

echoVariables ()
{ writelog "Log Process: ${logProcess}" writelog "User: ${userName}" writelog "Protocol: ${protocol}" writelog "Server: ${serverName}" writelog "Sharename: ${shareName}"
}

checkUsername ()
{ # Checks if the username variable is empty (user running script from Self # Service) if [[ -z "${userName}" ]]; then userName=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + " ");') fi
}

mountShare ()
{ mount_script=`/usr/bin/osascript > /dev/null << EOT # tell application "Finder" activate mount volume "${protocol}://${serverName}/${shareName}" # end tell
EOT` exitStatus="${?}"
}

Run script

echoVariables
checkUsername
mountShare
writelog "Script completed."

My question is has anyone out there ever used SID's to map network drives on a Mac? I've been trying everything I can think of to get this to work and am totally frustrated right now. Thank you in advance!!!

1 REPLY 1

Not applicable

you can try this function and see if it works for you:

mount_share () {
    osascript <<EOF 
    set serverName to "ServerName.company.org"
    set sharedResource to "ShareName"
    set serverPath to ((path to startup disk as text) & "Volumes:" & sharedResource & "")
    tell application "Finder"
    if not (exists folder serverPath) then
        mount volume "smb://" & serverName & "/" & sharedResource
        else
            return "" & sharedResource & " already mounted"
        end if
    end tell
EOF
}