Posted on 05-07-2018 09:44 PM
I have no scripting knowledge, found this script below which works for me for mounting the same network share for every user that logs in.
But for our lab we have multiple local accounts and each connects to a different share folder. Is it possible to create a script that will look up the logged in user and mount a network folder based who the logged in user is??
#!/bin/sh
protocol="$4" # This is the protocol to connect with (afp | smb)
echo "Protocol: $4"
serverName="$5" # This is the address of the server, e.g. my.fileserver.com
echo "Server: $5"
shareName="$6" # This is the name of the share to mount
echo "Sharename: $6"
# Mount the drive
mount_script=`/usr/bin/osascript > /dev/null << EOT
tell application "Finder"
activate
mount volume "$protocol://${serverName}/${shareName}"
end tell
EOT`
exit 0
Solved! Go to Solution.
Posted on 05-08-2018 07:34 PM
Never mind, I managed to make a script that works for me.
Here is what i used
#!/bin/sh
# Get the username of the currently logged in user
loggedInUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }')
# USER1
if [ "$loggedInUser" = "USER1" ]; then
protocol="$4" # This is the protocol to connect with (afp | smb)
echo "Protocol: smb"
serverName="$5" # This is the address of the server, e.g. my.fileserver.com
echo "Server: SERVER"
shareName="$6" # This is the name of the share to mount
echo "Sharename: SHARENAME_1"
# Mount the drive
mount_script=`/usr/bin/osascript > /dev/null << EOT
tell application "Finder"
activate
mount volume "smb://SERVER/SHARENAME_1"
end tell
EOT`
fi
# USER2
if [ "$loggedInUser" = "USER2" ]; then
protocol="$4" # This is the protocol to connect with (afp | smb)
echo "Protocol: smb"
serverName="$5" # This is the address of the server, e.g. my.fileserver.com
echo "Server: SERVER_2"
shareName="$6" # This is the name of the share to mount
echo "Sharename: SHARENAME_2"
# Mount the drive
mount_script=`/usr/bin/osascript > /dev/null << EOT
tell application "Finder"
activate
mount volume "smb://SERVER_2/SHARENAME_2"
end tell
EOT`
fi
Posted on 05-08-2018 07:34 PM
Never mind, I managed to make a script that works for me.
Here is what i used
#!/bin/sh
# Get the username of the currently logged in user
loggedInUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }')
# USER1
if [ "$loggedInUser" = "USER1" ]; then
protocol="$4" # This is the protocol to connect with (afp | smb)
echo "Protocol: smb"
serverName="$5" # This is the address of the server, e.g. my.fileserver.com
echo "Server: SERVER"
shareName="$6" # This is the name of the share to mount
echo "Sharename: SHARENAME_1"
# Mount the drive
mount_script=`/usr/bin/osascript > /dev/null << EOT
tell application "Finder"
activate
mount volume "smb://SERVER/SHARENAME_1"
end tell
EOT`
fi
# USER2
if [ "$loggedInUser" = "USER2" ]; then
protocol="$4" # This is the protocol to connect with (afp | smb)
echo "Protocol: smb"
serverName="$5" # This is the address of the server, e.g. my.fileserver.com
echo "Server: SERVER_2"
shareName="$6" # This is the name of the share to mount
echo "Sharename: SHARENAME_2"
# Mount the drive
mount_script=`/usr/bin/osascript > /dev/null << EOT
tell application "Finder"
activate
mount volume "smb://SERVER_2/SHARENAME_2"
end tell
EOT`
fi
Posted on 05-08-2018 10:05 PM
Good to know!! Sharing would help others :)