linux - 如何使用for循环检查Linux中的挂载点

标签 linux bash

我想写一个 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/

相关文章:

bash - 检查文件是否在 bash 中的给定目录(或子目录)中

bash - 提示中的 Git 分支

c - 在 Linux 中测量进程统计信息

java - 如何正确设置JAVA_HOME环境变量?

linux - Awk、tail、sed 或其他——对于大文件,哪个更快?

python - 在 python 中操作函数输出

c - exec 和 execve 等系统调用的 exec 系列的功能有什么区别?

c - 存储数十亿整数的数据结构

linux - 我组中的用户无法在 python 中导入 boxsdk(SyntaxError : invalid syntax )

linux - 使用 shell 脚本搜索和替换文件内容