手机
当前位置:查字典教程网 >脚本专栏 >linuxshell >Shell脚本实现监控iptables运行状态
Shell脚本实现监控iptables运行状态
摘要:最近在调试服务器的iptables,自己做了个定时关iptables,但晚上回家很少开电脑,所以就没法去启动iptables,当然你可能会说...

最近在调试服务器的iptables,自己做了个定时关iptables,但晚上回家很少开电脑,所以就没法去启动iptables,当然你可能会说,为什么不取消定时关闭iptables,我只能说个人的环境不一样,需求也就不一样.

脚本内容:

vi 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

验证图:

Shell脚本实现监控iptables运行状态1

大家可以先在虚拟机里测试下,再放到服务器上执行,当然如果你服务器性能好,也可以改成死循环去检测的.

【Shell脚本实现监控iptables运行状态】相关文章:

Shell脚本实现监控iptables规则是否被修改

shell脚本学习与总结

shell脚本实现快速生成xml格式sitemap实例分享

防止shell脚本重复执行的代码

Shell脚本实现批量替换文件内容

shell脚本监控系统负载、CPU和内存使用情况

Shell脚本实现随机数多种方法介绍(date、random、uuid)

shell脚本结合iptables防端口扫描的实现

Shell脚本数组用法小结

Shell脚本实现IP地址合法性判断

精品推荐
分类导航