Tec(h)tonic

Insights into building a solid I.T. foundation in the mid-size business world.

Shell script to force share unmount

hard-driveSome of my users have recently run in to a problem where a mounted file share begins to malfunction. Specifically, the share no longer appears to be mounted to the system (no desktop icon, no line item along the left-side nav bar in Finder windows) yet, when one goes to (re)mount the share, the “Connect to Server” dialog box displays the share’s name in grey, as if it was still mounted.

While I’m not 100% certain what causes this (my best guess is either the laptop going to sleep, a brief drop in network connectivity or a transition between Ethernet and wifi), I did come up with a quick-and-dirty shell script that can be used to forcibly unmount the troublesome shares.

#!/bin/sh
# CJS: Quick and dirty way to unmount volumes when they get “lost” after network disconnect
# list each share served by the file server
diskutil unmount /Volumes/<share01>
diskutil unmount /Volumes/<share02>
# re-mount each share
mount -t smbfs //<fileServerFQDN>/<share01> /Volumes/<share01>
mount -t smbfs //<fileServerFQDN>/<share02>
/Volumes/<share02>

For the sake of being more universal, I simply listed each of the shares available on <fileServerFQDN>, unmounting each of them using the diskutil unmount command and then re-mount all of them using the mount command.

Save this as a text file with a .sh extension, set it to be opened, by default, with the Terminal app and then any given client can doube-click this for an easy fix whenever they run in to this issue.

Note that my example is for mounting Samba-based shares, though the mount command can mount all types of share – see the man page for full details.


Leave a Reply

Your email address will not be published. Required fields are marked *