Thursday 18 April 2019

macos - OSX / Samba - How do I automatically remount / reconnect to drives that have been disconnected?


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.



Answer



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='myemail@address.com'
###################################
# 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

No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...