Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

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
share|improve this answer
    
Thanks! This was very helpful :) –  John2496 Apr 26 '11 at 19:10
add comment

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.

share|improve this answer
1  
OK, 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. –  andsens Jun 22 '11 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 ;) –  John2496 Jun 23 '11 at 5:37
add comment

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.

share|improve this answer
    
How would I envoke Finder from a shell script? Its an automated script, so everything would need to be done via shell. –  John2496 May 2 '11 at 19:29
    
You only have to create the alias once which can be done from the GUI. –  namsral May 3 '11 at 8:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.