创建要检测的脚本
现行制度:
从理论上讲,它一定起作用了,但缺少了一些东西:
#!/bin/bash
installer_check () {
if [[ $(apt-get -V >/dev/null 2>&1) -eq 0 ]]; then
installer=apt
elif [[ $(yum --version >/dev/null 2>&1) -eq 0 ]]; then
installer=yum
fi
}
frw_det_yum () {
if [[ $(rpm -qa iptables >/dev/null 2>&1) -ne 0 ]]; then
ipt_status_y=installed_none
elif [[ $(rpm -qa firewalld >/dev/null 2>&1) -ne 0 ]]; then
frd_status_y=installed_none
fi
}
frw_det_apt () {
if [[ $(dpkg -s iptables >/dev/null 2>&1) -ne 0 ]]; then
ipt_status_a=installed_none
elif [[ $(dpkg -s firewalld >/dev/null 2>&1) -ne 0 ]]; then
frd_status_a=installed_none
fi
}
echo "checking installer"
installer_check
echo -e "$installer detected"
if [ "$installer" = "yum" ]; then
echo "runing firewallcheck for yum"
frw_det_yum
echo $ipt_status
fi
if [ "$installer" = "apt" ]; then
echo "checking installer for apt"
frw_det_apt
echo $frd_status_a
fi我得到的输出:
~# ./script
checking installer
apt detected
checking installer for apt因此,在当前的系统中,我对$frd_status_a没有任何价值。
发布于 2017-04-02 17:46:33
如果没有安装firewalld,您希望调用以下内容的主体:
if [[ $(dpkg -s firewalld >/dev/null 2>&1) -ne 0 ]]; then
frd_status_a=installed_none
fi然而,让我们来看看它到底做了些什么:
dpkg -s firewalld的stdout和stderr重定向到/dev/null0进行数字比较对于,无论在调用dpkg命令时做什么,也不管它的输出是什么,都不会设置该标志。
相反,请考虑:
if ! dpkg-query -l firewalld; then
frd_status_a=installed_none
fihttps://stackoverflow.com/questions/43171280
复制相似问题