检查/etc/resolv.conf是否为空的shell脚本
时间: 2023-12-19 10:07:14 浏览: 116
判断文件是否存在的shell脚本代码
#!/bin/bash
if [[ ! -s "/etc/resolv.conf" ]]; then
echo "The file /etc/resolv.conf is empty"
else
echo "The file /etc/resolv.conf is not empty"
fi
Explanation:
This script checks if the file /etc/resolv.conf is empty or not. The "-s" option of the "test" command (also known as "[") returns true if the file exists and has a size greater than zero. The "!" operator negates the test, so the script echoes a message indicating that the file is empty if the test fails (i.e., the file does not exist or has a size of zero). If the test succeeds, the script echoes a message indicating that the file is not empty.
阅读全文