linux关闭防火墙小脚本
#!bin/bash
sleep 5
#关闭linux防火墙
a=$(iptables -L | grep anywhere | wc -l)
if [ $a -eq 0 ] ; then
echo "防火墙已关闭"
exit
else
#判断是c6还是c7
if egrep "7.[0-9].[0-9]" /etc/redhat-release &> /dev/null;then
echo $?
systemctl stop firewalld.service && systemctl enable firewalld.service
if [ $? -eq 0 ] ;then
echo "防火墙已由开启状态变为关闭状态"
exit
else
echo "防火墙未关闭异常!!"
exit
fi
elif egrep "6.[0-9].[0-9]" /etc/redhat-release &> /dev/null;then
echo $?
service iptables stop && checkconfig iptables off
if [ $? -eq 0 ] ;then
echo "防火墙已由开启状态变为关闭状态"
exit
else
echo "防火墙未关闭异常!!"
exit
fi
fi
fi
常见报错:basic.sh: 第 7 行:[: enforcing: 期待整数表达式
"-eq" 对整数进行比较 如数字
"==" 对字符串进行比较 如“dhdj454”