Posted on 04-28-2015 10:13 PM
Hi All,
I'm looking for a script that can mount network drives and be able to have it displayed on the desktop or even in the sidebar in finder.
Using Yosemite 10.10.3
Posted on 04-28-2015 10:41 PM
I use the following login hook. It uses Kerberos authentication but you could use name and password. You can replace the afp:// with smb:// was well.
#!/bin/sh
user=$1
server=hostname.of.server
share=ShareName
# Mount network share as user
sudo -u $user mkdir /Volumes/$share
sudo -u $user mount_afp "afp://;AUTH=Client%20Krb%20v2@$server/$share" /Volumes/$share
if [ $? ]
then
rmdir /Volumes/$share
fi
exit 0
Posted on 04-29-2015 02:03 AM
Posted on 04-29-2015 07:02 AM
I know you mentioned a script, but there are also configuration profile "Login Items" options to mount network shares — in Profile Manager (at least v4) and JSS (at least 9.7). I have not tried them, so not sure whether or not they work — or how well.
Posted on 04-29-2015 01:40 PM
We've tried the login item route with config profiles as it would have been a good quick win, but we got bitten. It was intermittently not working and removing the profile left the login item in place so we could remove, only add.
If it's any help we've been using this script recently to mount drives:
#!/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
We add it to the JSS and set the necessary labels for $4, $5 & $6. It can then be used in lots of policies just by setting the necessary values.
We've used the mount_afp
method as well, but there has to be quite a lot of logic when you use if $? rmdir
. There are quite a few scenarios that can cause a false positive and then proceed to empty the network drive. This is one of the reasons we now prefer AppleScript mounting.
Posted on 05-13-2015 07:44 AM
We use a script:
sudo -u $3 /usr/sbin/jamf mount -server BAN-S.ANDOVERMA.LOCAL -share COMMON-S -type smb -visible
exit 0
Replace the server's fqdn and share name with yours. I found this on JAMF Nation and its been working great. I was using a Configuration profile to do it but it takes a couple of logins to get it to show up which was not ideal in a lab environment where users didn't always use the same computer.
Posted on 05-13-2015 07:48 AM
Maybe someone can help me. My script is mounting network shares but my home directory would mount on its own and show a folder on the dock. That broke when I upgraded from Casper 8 to 9. All I would see on the dock was a question mark. JAMF sent me a script called fixquestionmark.sh which worked great until I tested it out on a Yosemite machine.
Any ideas?
Posted on 05-15-2015 01:49 AM
@msnowdon I thought the home folder was mounted & added to the dock as part told the AD binding? I've not done that for a while but is that something you can try?
Posted on 05-15-2015 02:59 AM
My understanding was the same as @bentoms, in that if you force a local home but leave the "Use UNC path..." option on, it would map the home folder and add it to the dock.
Normally, if there's a "?" then it didn't mount or mounted after the dock loaded. Unfortunately this is why we implemented our own system to map a user's home folder. Not seen it as part of Casper related behaviour I'm afraid!
Darren
Posted on 05-18-2015 05:11 AM
I have my computer bound to AD with those items selected. It mounts the home folder in the dock just fine until I enroll the computer into Casper. Then I just get a question mark. This behavior started back when we upgraded the JSS from 8 to 9. JAMF support sent me a script which fixed the problem until I started playing around with Yosemite.
I was able to find another script on JAMF Nation to mount the home directory with Yosemite but I still see the question mark unless I go back into the Directory Utility and uncheck the option "use UNC path..."
Thanks for the input.
Mark
Posted on 05-19-2015 12:26 PM
@msnowdon is the JSS managing some dock settings then?
Posted on 05-19-2015 12:52 PM
No but for the heck of it I went back into my Yosemite machine and re-checked the option in the Directory Utility to "Use UNC path...", rebooted and it loaded the home directory on the dock! No question mark this time.
I've been making a lot of tweaks such as converting all my MCX Preferences to Configuration Profiles since Yosemite doesn't recognize them but I'm not sure what I changed that corrected the issue.
But thanks for your help Ben.
Posted on 07-11-2016 10:21 AM
Just a follow-up:
I use David's AppleScript idea and it has worked great. Much better than the unix mount commands.
I want to clean the code up a bit (make it easier to read, more modular etc). So I am going to rewrite my mount scripts soon. I'm playing with a few ideas.
My objectives:
1) Convert the AppleScript mount code into a function.
2) Replace the backticks with $(). This command substitution and elimantion of the EOT (here document) appears to be my problem - see below,
3) Misc cosmetic changes to keep things tidy, modern and consistent.
Im having issues here. Beating head against a desk. Script wont exit. Just spins forever. Everything looks good to me. Need a sanity check, please!
David's original code (from earlier in this post):
mount_script=`/usr/bin/osascript > /dev/null << EOT
tell application "Finder"
activate
mount volume "$protocol://${serverName}/${shareName}"
end tell
EOT`
My proposed changes:
function mountAppleScript() {
input=$(/usr/bin/osascript &>/dev/null
tell application "Finder"
mount volume "${protocol}://${serverName}/${shareName}"
end tell)
}
mountAppleScript
Posted on 09-08-2016 09:58 PM
@dstranathan Did you ever get an answer on this?
Posted on 09-09-2016 06:25 AM
Yes, I revised my SMB mount scripts this summer. The AppleScript function looks like this:
function AppleScript_Mount()
{
mount_script=`/usr/bin/osascript > /dev/null << EOT
tell application "Finder"
mount volume "${protocol}://${serverName}/${shareName}"
end tell
EOT`
}