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.

There's a myriad of possibilities for mounting shares upon Login within OSX. I'm after having it done when a network connection is restored.

Ideally:

  • Mount the share
  • connection lost
  • connection re-gained
  • Mount the share again (if possible), otherwise, don't - i.e. different location.

Any idea as to how to make this happen?

Am exploring the possibility using NFS shares from the DroboFS, but would prefer to keep it to CIFS/AFP.

Suggestions are welcome.

Thank you.

share|improve this question
add comment

1 Answer

You could try something like this:

last_status=0                                                                                  

while :                                                                                        
do                                                                                             
    ping -t 1 google.com > /dev/null 2>&1                                                      
    exit_status=$?                                                                             

    if [[ $exit_status == 0 && $last_status != 0 ]]; then                                      
        last_status=$exit_status                                                               
        osascript -e 'tell application "Finder"' -e 'eject "share"' -e 'end tell'                  
        osascript -e 'tell application "Finder"' -e 'open location "smb://server/share"' -e 'end tell'                                                                                      
    else                                                                                       
        last_status=$exit_status                                                               
    fi                                                                                         
    sleep 5                                                                                    
done        

We check the internet connection by pinging google, you could change that to a local IP if you don't want to test for internet connectivity. If we can ping google then we tell finder to eject the old mount, and mount a the SMB share again, otherwise sleep for 5 seconds.

It's very dirty but it does what you want, there is a lot of room for improvements.

share|improve this answer
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.