欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Shell腳本實(shí)現(xiàn)監(jiān)控iptables規(guī)則是否被修改

 更新時(shí)間:2014年12月31日 11:33:38   投稿:junjie  
這篇文章主要介紹了Shell腳本實(shí)現(xiàn)監(jiān)控iptables規(guī)則是否被修改,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下

最近看了一篇通過(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

復(fù)制代碼 代碼如下:

#!/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è)一次.

復(fù)制代碼 代碼如下:

chmod +x /root/check_iptables.sh
*/3 * * * * /bin/sh /root/check_iptables.sh

當(dāng)然你也可以加上郵件報(bào)警來(lái)通知iptables規(guī)則有改變.

相關(guān)文章

最新評(píng)論