I have a SMB share via my router that I use to share docs between 4 rPi4B's. I mount the drive on boot via gstab with the following line:

//fritz.box/fritzbox/NAS_USB    /home/pi/Documents/Dateiserver  cifs    vers=1.0,credentials=/home/pi/.smbcredentials,uid=1000,gid=1000,sec=ntlm,       0       0

Every once in a while the fileserver will go offline and this means that the 4 Pi's all lose access to the shared files. I know it's a simple step for me to open a terminal and run mount -a but it's not practical to get others in the office to do this and I'm not always around when it happens.

Is there an efficient way of remounting the network share when it becomes available again?

I know I could run mount -a every few minutes as a cron job but that just seems like it should be an absolute last option.

1 Answer 1


You could check if the fs are online, and then, and only then run mount command.

a possible solution could be:

online_disk=`2>/dev/null df -t cifs | wc -l`

[ $online_disk -gt 0 ] || muont -a

This two line of code check for cifs mount, if the device are online there are some line and it skip, otherways it run the mount cmd. Schedule it with cron

  • Can this be run as one line? If not how would it be added to cron? Excuse my ignorance. Feb 11, 2021 at 23:37
  • 1
    Yes you could: [[ `2>/dev/null df -t cifs | wc -l` -eq 0 ]] || mount -a You need to add the double square brackets Feb 11, 2021 at 23:50
  • Great. I'll give that a go. Thanks. Feb 11, 2021 at 23:52

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.