I have remotely mounted a filesystem using SSHFS to directory /mnt/sshfs
.
I need to find out using a shell script if this SSHFS mount is working correctly or if there is a connection reset by peer
problem.
If I try to access such an SSHFS filesystem if it is in "disconnected state", the system freezes and waits until it eventually times out.
I want to avoid that. I need to know if SSHFS is working as expected or if there is some connection problem without freezing the system.
As far as I can tell, SSHFS has no other means of checking connectivity other then trying to access a file and failing.
You should be able to specify SSH options when mounting SSHFS that specify things like ServerAliveInterval and ServerAliveCountMax (see man ssh_config
) that will terminate your SSH connection "early". Also make sure to use TCPKeepAlive to kill the connection if your internet connection should drop.
What I'd say would be an interesting way to tackle the problem of knowning the connection state would be to extend sshfs (which isn't really that complicated a FUSE module), and add an ioctl
that you could query to figure out whether everything is in order, without blocking if it wasn't.