Custom Names for SMB shares on OSX

1

I have a number of (windows) networked drives that I need to connect to using my Mac - the trick is that on many of these servers I'd like to be able to connect directly to the c$ share. So I end up with a list of mounted volumes that look like:

/Volumes/C$
/Volumes/C$-1
/Volumes/C$-3
/Volumes/c$-2

Which causes great confusion in some of my applications.

My question is: Can I specify a custom name for a mount point? Something like:

/Volumes/server1
/Volumes/server2
/Volumes/server3

I haven't been able to Google up any solutions for doing this, but I suspect that it should be possible. I currently connect using an Automator script, but I'm not afraid to shell script it either.

...or am I thinking about this the wrong way?

Thanks for your consideration...

gabeuscorpus

Posted 2014-07-01T13:10:41.000

Reputation: 11

Answers

4

You can do this in a shell script with something like:

#!/bin/bash

mountpoint='/Volumes/server1'
serverpath='server1.wibble.com/C$'
username='gabeuscorpus'

if [[ -e "$mountpoint" ]]; then
    echo "Error: the path $mountpoint is already in use' >&2
    exit 1
fi

mkdir "$mountpoint" || {
    echo "Error creating mount point" >&2
    exit 1
}

mount -t smbfs "//$username@$serverpath" "$mountpoint" || {
    echo "Error mounting smb://$mountpoint" >&2
    rmdir "$mountpoint"
    exit 1
}

There are some caveats with this method: first, while this mounts the server volume under the path /Volumes/server1, it'll still show up in the Finder as C$. Programs that access files by path will not be confused, but you will be.

Second, this will prompt for the server password in Terminal. It would possible to include the password in the form "//$username:$password@$serverpath", but then the password is visible to anyone who does a ps listing. Unfortunately, it does not seem to use passwords stored in the keychain.

Finally, the /Volumes directory is normally used by OS X's various built-in volume mounting systems; I don't think adding manually mounted volumes will cause trouble, but there's a small risk of a conflict.

Gordon Davisson

Posted 2014-07-01T13:10:41.000

Reputation: 28 538