Skip to main content
Question

Mount Network Drive

  • April 29, 2015
  • 14 replies
  • 111 views

Forum|alt.badge.img+3

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

14 replies

c_kay
Forum|alt.badge.img+10
  • Contributor
  • April 29, 2015

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


bentoms
Forum|alt.badge.img+35
  • Hall of Fame
  • April 29, 2015

@Luket We use this

@c.kay Loginhook or launch agent?


Forum|alt.badge.img+9
  • Contributor
  • April 29, 2015

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.


davidacland
Forum|alt.badge.img+18
  • Valued Contributor
  • April 29, 2015

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.


Forum|alt.badge.img+10
  • Contributor
  • May 13, 2015

We use a script:

!/bin/bash

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.


Forum|alt.badge.img+10
  • Contributor
  • May 13, 2015

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?


bentoms
Forum|alt.badge.img+35
  • Hall of Fame
  • May 15, 2015

@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?


daz_wallace
Forum|alt.badge.img+13
  • Contributor
  • May 15, 2015

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


Forum|alt.badge.img+10
  • Contributor
  • May 18, 2015

@bentoms & @daz_dar ,

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


bentoms
Forum|alt.badge.img+35
  • Hall of Fame
  • May 19, 2015

@msnowdon is the JSS managing some dock settings then?


Forum|alt.badge.img+10
  • Contributor
  • May 19, 2015

@bentoms

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.


dstranathan
Forum|alt.badge.img+19
  • Valued Contributor
  • July 11, 2016

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


Forum|alt.badge.img+6
  • Contributor
  • September 9, 2016

@dstranathan Did you ever get an answer on this?


dstranathan
Forum|alt.badge.img+19
  • Valued Contributor
  • September 9, 2016

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`
}