iptables恢复脚本

Posted on 2020-04-23 14:26  hrers  阅读(300)  评论(0编辑  收藏  举报

#!/bin/bash


PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
ACTIVE=`systemctl status iptables.service |grep 'active' |awk '{print $2}'`
INACTIVE=`systemctl status iptables.service |grep 'inactive' |awk '{print $2}'`
Date=`date +%Y-%m-%d-%H-%M`
if [ $ACTIVE = "active" ];then
iptables-restore </root/iptables.restore
echo "restore success!">/tmp/restore.log
mail -s "iptables status $Date" wd.zhao@qq.com</tmp/restore.log >/dev/null 2>&1
elif [ $INACTIVE = "inactive" ];then
systemctl restart iptables.service
STATUS1=`systemctl status iptables.service |grep 'active' |awk '{print $2}'`
STATUS2==`systemctl status iptables.service |grep 'inactive' |awk '{print $2}'`
if [ $STATUS1 = "active" ];then
iptables-restore </root/iptables.restore
echo "restore success!">/tmp/restore.log
mail -s "iptables status $Date" wd.zhao@qq.com</tmp/restore.log >/dev/null 2>&1
elif [ $STATUS2 = "inactive" ];then
echo "iptables is bad!please check it." >>/tmp/iptables.log
mail -s "iptables status $Date" wd.zhao@qq.com</tmp/iptables.log >/dev/null 2>&1
fi
else
echo "please check out iptables message.Is it installed?">>/tmp/iptables.log
fi