当前位置: > shell编程 >

如何用shell脚本监控iptables运行状态

时间:2015-01-02 15:04来源:linux.it.net.cn 作者:IT
分享一段shell脚本,用于监控iptables运行状态,当检测到iptables停止运行时,可以重启iptables服务。

shell脚本监测iptables运行状态
iptables-reset.sh
 

 
#!/bin/bash
#Powered by blog.slogra.com
port=`iptables -vL|grep ssh|awk '{split($NF,a,":");print a[2]}'|wc -l`
if [ $port = 1 ];then
echo "ok!"
else
/etc/init.d/iptables start
sleep 2
port=`iptables -vL|grep ssh|awk '{split($NF,a,":");print a[2]}'|wc -l`
if [ $port = 1 ];then
echo "ok!"
else
/etc/init.d/iptables restart
fi
fi

验证效果:
<a  data-cke-saved-href=http://www.jbxue.com/jb/shell/ href=http://www.jbxue.com/jb/shell/ target=_blank class=infotextkey>shell</a>脚本监控iptables运行状态

有了这段shell脚本,就可以监测iptables的实时运行状态了,避免服务停止了,自己却不知道。

(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容