Is there a simple method to automatically reconnect a network drive that has been disconnected due to network failure or some other issue. I have a batch job setup that periodically copies files to a network drive, when the drive disconnects, I need to manually remount the drive.
3 Answers
Add some code to check for the mounts and to try and remount them if needed - here's some (snipped bits) from a Linux backup bash script (sorry, no OSX to hand at the moment) - it might give you some pointers and maybe someone will post an OSX equivalent too:
thishost='myhostname'
#
mountpoint='/root/mybackup'
#
mountoptions='-o username=bkuplinux,domain=mydomain,password=mypassword'
#
sharename='//ssc4/linux'
#
emailtarget='[email protected]'
###################################
# End of user editable variables
###################################
backupfolder=$mountpoint/$thishost
if [ $(mount | grep -c $mountpoint) != 1 ]; then
echo "$mountpoint mount is not present - trying to mount..."
mount -t cifs $sharename $mountpoint $mountoptions
if [ $(mount | grep -c $mountpoint) != 1 ]; then
echo "$mountpoint mount is still not present - quitting"
if [ "$emailtarget" != "" ]; then
echo "$mountpoint mount is not present on $thishost so backup cannot continue" | mail -s "$thishost backup problem" $emailtarget
fi
exit 1
fi
fi
You don't need a cronjob to poll the network share.
Creating and saving an alias of the network drive in the Finder will have the Finder automatically mount the network drive when it becomes available.
-
How would I envoke Finder from a shell script? Its an automated script, so everything would need to be done via shell.– John2496May 2, 2011 at 19:29
-
You only have to create the alias once which can be done from the GUI. May 3, 2011 at 8:11
Access the drive via Finder, this will automatically mount it in /Volumes.
Go there (Cmd+Shift+G), right click the mounted Volume and create an alias.
Now you can copy this alias wherever you like.
I used to symlink to /Volumes/MyShare with ln -s
, this solution does not remount the drive however.
-
1OK, I just figured out that this wont work with the commandline. It seems the aliases that the Finder creates are data files, just like Windows shortcuts and not mounts. You can try looking up autofs though, it seems to have the feature you request.– andsensJun 22, 2011 at 20:07
-
thanks as a clumsy hack fix, I wrote a script to check for a known folder on the network drive mount. If the folder isn't found, then it mounts the fs via 'mount -t smbfs'. It doesn't mount to the finder mount points though. edit: sort of like the first answer ;)– John2496Jun 23, 2011 at 5:37