I'm pretty new to mount. Basically, I have a remote SMB serv on the local network that I want copy images from a directory on, then repeat every 5 min.

I think what I need to do is make a script that checks to see if the server is mounted, if it isn't mount it, if it is, do nothing, then run rsync.

I was able to setup crontab (for the first time) to remove all the existing files in the directory and then runrsync, but I'm not sure how I should approach the SMB stuff. Should I mount it, copy the files and unmount, or should I leave the connection be?

Btw, I'm using OSX.


If your servers are expected to be up and connected most of the time, then I'd say leave the mount in place. That way you avoid some overhead establishing the connection. If, on the other hand, you have network dropouts or similar connection issues, then having an active mount might cause data loss for newly written files, because the filesystem won't be cleanly unmounted when the network goes away. It might be prudent to add the --checksum flag to rsync after such an unintended unmount, so that not only file modification times (assuming --times) but file content as well gets checked. That should reduce adverse effects from forced unmounts.

To check whether something is mounted, simply grep for it in the output of mount.

Also note the soft and hard options to mount.cifs, which will decide whether a broken connection will cause read errors or program hangs. I'm pretty sure that with the hard option, you'd see a remote as mounted even if the connection failed. With soft, I'm not sure at all. If you see the filesystem still mounted, then chances are good that you'll be able to access it when the connection is restored. If the connection isn't available, though, the hard option will cause your rsync to hang.

  • Thanks for the help. Would you happen to know how I can validate the connection in a shell script? For example, if the connection can't connect, I don't want to run the rest of the script – nipponese Jul 23 '12 at 22:44
  • @nipponese: It the fs isn't mounted up front, you could issue a mount and check the output from mount afterwards. If the fs is mounted and you want to know whether it actually is available, try writing to a randomly generated temporary file or similar. But if the fs was mounted hard, this will make your script hang. – MvG Jul 24 '12 at 7:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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