创建脚本以检测
- 安装程序(yum 或 apt-get)
- iptables
- 防火墙
当前系统:
- Debian 8
- iptables 未安装
- 未安装防火墙
理论上它必须工作,但缺少一些东西:
#!/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