A way to test a samba share without hanging

If a mounted samba share becomes inaccessible, any attempt to access the corresponding mount point results in a hanging terminal. I can use

umount -l

to unmount the share and then

mount -t cifs ...

to mount it back if the corresponding server is functioning properly again. Now, I would like to do unmounting/remounting in an automated way: a script should check all shares from the list (our server has access to about 10 shares), find the faulty ones and unmount them. Is there a way to test for a faulty mount without hanging the script? I tried to use

timeout -k 1s -s SIGKILL 1s grep alive /"$share"/status.txt

where status.txt should be a text file placed into each share and containing the line “alive” so that if share is mounted properly grep returns “alive” but grep just hangs if the share is faulty hanging the whole script. Is there a way to kill such hanging process immediately and utterly after a certain timeout? Or is there any other (and perhaps more elegant) ways to check faulty shares without hanging?

The server uses Leap 42.1 with a 4.1.34-33-default kernel.

Any suggestions?

iMO it might be important how you’re mounting your network shares in the first place…

The following describes a method to mount network shares by creating a systemd Unit file which might be superior to specifying entire mount commands so you can simplify invocation…
If you do this, it provides an easy, re-usable way to manage your network share using common systemctl stop|start|restart commands which can be scripted or manually invoked however you wish

http://wiki.openelec.tv/index.php/Mounting_network_shares

If you’re asking for a script that walks through each network share and tests either by checking for the existence of a valid path, you’ll probably need to provide the actual share paths. You can probably also check only for network connectivity to a remote server(eg ping), but that would only verify a working network connection, not necessarily a working network share.

HTH,
TSU

FYI -
Out of curiosity,
Took a look at what Arch Wiki might have to say about this and the last sections on this page describe setting up systemd services, a cron timer or networkdispatcher, and using ping(or better yet a TCP probe using the port your network share is using)
https://wiki.archlinux.org/index.php/NFS#Mount_using_autofs

Although the page is for mounting and optionally auto-mounting (and re-mounting) NFS shares, everything I see can be easily adapted to CIFS (ie SAMBA) shares easily.

TSU