Frodik
Frodik

Reputation: 15455

How to find out if sshfs mounted directory is not disconnected?

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.

Upvotes: 3

Views: 4888

Answers (3)

mmrtnt
mmrtnt

Reputation: 139

You can use "mountpoint". I just found out about it in this thread:

https://unix.stackexchange.com/a/39110

I tested it with sshfs and it reports "is a mountpoint" and "is not a mountpoint"

Upvotes: 0

monkey
monkey

Reputation: 71

I guess just grep the mount command?

if (( $(mount | grep -e 'whatever you like'| wc -l) > 0 ));
then     
echo "mounted"; 
fi

Upvotes: 4

Marcus Müller
Marcus Müller

Reputation: 36337

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.

Upvotes: 0

Related Questions