Score:0

Check if network drive is mounted in a timely manner

zw flag

I have a network drive mounted through cifs with the following configuracion in fstab:

/ip/drive /local_path cifs username=username,password=password,acl,rw 0 0

I need to know as soon as possible if the network drive is offline / not accessible.

Currently, i have a separate service running ls command periodically on the mounted path and checking if command gives a network error, but the moment the drive comes offline, ls command takes about 3 minutes to fail.

I could run the command with a timeout (timeout 10 ls /local_path) but is there a better way to know if the drive is down without waiting for ls command to fail?

pl flag
You could reduce the 3 minutes with the addition of the `x-systemd.device-timeout=10s` option in your fstab after the `rw`. Choose some value for the time out which is suitable. You could also script just checking for the existence of a file, rather than a full `ls`. A few lines of bash could just `test /localpath/lost+found` for example, to see if it's there quickly.
cn flag
doing it using inotify / udev would be quicker (ie. real time). But i do agree with popey: checking for the existance of 1 file or a directory should be enough. The mount command itself can tell you if something is mounted too. also possible:put it into a systemd unit and then you can have it remount on failure.
hr flag
I wonder if the `mountpoint` command would be useful here?
Ulisha avatar
zw flag
@popey Funly enough, I tried to check for the existence of a specific file before trying the ls command. Ubuntu tels me the file exists even when the network drive is down. I will be trying the x-systemd.device-timeout next.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.