您现在的位置是:网站首页> 编程资料编程资料
Shell脚本实现监控iptables运行状态_linux shell_
2023-05-26
349人已围观
简介 Shell脚本实现监控iptables运行状态_linux shell_
最近在调试服务器的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脚本实现监控rsync数据是否传输完_linux shell_
- Shell脚本实现监控kingate并自动启动_linux shell_
- Shell脚本实现监控iptables规则是否被修改_linux shell_
- expect实现单台、多台服务器批量scp传输文件_linux shell_
- Shell脚本实现关闭多余的tty终端_linux shell_
- Shell脚本中实现切换用户并执行命令操作_linux shell_
- Shell脚本自动删除指定大小以上的备份文件_linux shell_
- Shell脚本实现批量替换文件内容_linux shell_
- expect实现批量修改linux密码脚本分享_linux shell_
- Shell命令批量修改图片文件名_linux shell_
