我想写一个 Bash 脚本,检查挂载点是否存在。如果确实如此,那么如果不是“睡 5 秒”,则执行“某事”。
我想写一个 for 循环,这样如果它最初被挂载,我可以检查相同的条件直到它为真
if mountpoint -q /foo/bar; then
/etc/init.d/iptables
else
sleep 5
fi
如何编写 for 循环来检查挂载点直到它存在?
最佳答案
这是一种方法:
mnt_path=/mnt/
while ! mountpoint -q "$mnt_path"; do
# mountpoint does not exist
sleep 5
done
# while loop exited, meaning mount point now exists
cat /etc/init.d/iptables
我建议引入超时。
关于linux - 如何使用for循环检查Linux中的挂载点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56908496/