Shell腳本實(shí)現(xiàn)監(jiān)控iptables規(guī)則是否被修改
最近看了一篇通過(guò)nagios實(shí)現(xiàn)MD5實(shí)時(shí)監(jiān)控iptables狀態(tài)的文章,就想是否可以用shell也做到監(jiān)控iptables規(guī)則改變,經(jīng)過(guò)實(shí)驗(yàn),就有了下面這個(gè)腳本.
系統(tǒng):centos 5.x
腳本內(nèi)容:
cat check_iptables.sh
#!/bin/bash
if [ ! -f .count ];then
iptables -L -n|md5sum|awk '{print $1}' > ~/.count
exit 1
else
iptables -L -n|md5sum|awk '{print $1}' >~/1.txt
difffile=`diff ~/.count ~/1.txt|wc -l`
if [[ $difffile = 0 ]];then
echo "file is ok!"
sleep 1
rm -f ~/1.txt
else
echo "file is no ok!"
cat ~/1.txt >~/.count
sleep 1
rm -f ~/1.txt
fi
fi
然后丟到crontab里.以每隔3分鐘檢測(cè)一次.
chmod +x /root/check_iptables.sh
*/3 * * * * /bin/sh /root/check_iptables.sh
當(dāng)然你也可以加上郵件報(bào)警來(lái)通知iptables規(guī)則有改變.
相關(guān)文章
Shell腳本實(shí)現(xiàn)批量替換文件內(nèi)容
這篇文章主要介紹了Shell腳本實(shí)現(xiàn)批量替換文件內(nèi)容,本文主要實(shí)現(xiàn)批量修改一個(gè)備份腳本里的備份路徑,其它批量替換也可以修改使用,需要的朋友可以參考下2014-12-12
Linux shell條件判斷if中的-a到-z的意思【推薦】
這篇文章主要介紹了Linux shell條件判斷if中的-a到-z的意思,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-08-08
Shell獲取路徑操作(dirname $0 pwd)的實(shí)現(xiàn)
在shell腳本中經(jīng)常會(huì)看到$(cd $(dirname $0); pwd)、basename等操作,本文主要介紹了Shell獲取路徑操作(dirname $0 pwd)的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02
linux下執(zhí)行shell命令方法簡(jiǎn)介
本文給大家分享的是linux系統(tǒng)下執(zhí)行shell命令的常用的2種方法,希望對(duì)初學(xué)shell命令的小伙伴能夠有所幫助2016-12-12

