简体   繁体   English

如何查看sshfs挂载目录是否断开?

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

I have remotely mounted a filesystem using SSHFS to directory /mnt/sshfs .我已经使用 SSHFS 将文件系统远程安装到目录/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.我需要使用 shell 脚本查明此 SSHFS 挂载是否正常工作或者是否存在connection reset by peer

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.如果我尝试访问处于“断开连接状态”的此类 SSHFS 文件系统,系统会冻结并等待直到它最终超时。

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.我需要知道 SSHFS 是否按预期工作,或者在不冻结系统的情况下是否存在连接问题。

As far as I can tell, SSHFS has no other means of checking connectivity other then trying to access a file and failing. 据我所知,SSHFS没有其他方法可以检查连接,然后尝试访问文件并失败。

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". 挂载SSHFS时,您应该能够指定SSH选项,这些选项指定诸如ServerAliveInterval和ServerAliveCountMax之类的内容(请参见man ssh_config ),这些内容将“提前”终止SSH连接。 Also make sure to use TCPKeepAlive to kill the connection if your internet connection should drop. 如果您的互联网连接断开,还请确保使用TCPKeepAlive终止连接。

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. 我所说的将是解决已知连接状态问题的有趣方法是扩展sshfs(这不是一个非常复杂的FUSE模块),并添加一个你可以查询的ioctl来确定是否一切是有序的,如果不是没有阻止。

I guess just grep the mount command? 我想只是grep mount命令?

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

You can use "mountpoint".您可以使用“挂载点”。 I just found out about it in this thread:我刚刚在这个线程中发现了它:

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

I tested it with sshfs and it reports "is a mountpoint" and "is not a mountpoint"我用 sshfs 测试了它,它报告“是一个挂载点”和“不是一个挂载点”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM