Bashshell程序片段来检查是否已安装的Samba共享不忙

#!/bin/sh mount -t cifs //192.168.5.90/share -o password='' /mnt/tera_nas rsync -av --super --delete --recursive /home/ /mnt/tera_nas/home/ # sleep 5m (i want to avoid using this) # Bash shell snippet to check if mounted Samba share is not busy before issuing umount command umount /mnt/tera_nas/ 

我只是懒惰卸载它,使用-l标志。 这将从文件系统中删除挂载点(因此不会有新的操作可以启动),并且在不再忙的时候完成正确的卸载。

你可以看看它是否有任何打开的文件描述符

你可以使用“fuser -m mountpoint”来查看是否有人正在访问path。

让我们为你做下功夫:

 while ! $(umount /mnt/tera_nas/ 2>/dev/null) do echo "not yet" sleep 5m done echo "now it is" 

你可以缩短睡眠时间,但我不会消除它。 它在这里担任的angular色不同于你的问题。

2 丹尼斯·威廉姆森 :

我宁愿使用

 umount -l /mnt/tera_nas 

最后。

使用automount执行此操作,mountpoint /mnt/tera_nas/home/将在访问时自动挂载,一旦不再需要时将挂载。

 # /etc/auto.master /mnt auto.mnt # /etc/auto.mnt tera_nas -t cifs,password='' ://192.168.5.90/share 

然后service autofs restart