inotify+sendEmail 搭建文件监控系统

下载inotify+sendEmail

wget http://csa.catelgame.com/down/inotify-tools-3.14.tar.gz

wget http://csa.catelgame.com/down/sendEmail-v1.55.tar.gz

下载完成后解压

安装inotify

进入安装包目录

./configure �Cprefix=../inotify && make && make install

echo $?

编写文件监控报警脚本

#i! /bin/bash
#by catelgame-sa-team anxiaodi
../inotifywait -mrq �Cexclude=”/跳过的路径/”�Ctimefmt ‘%y/%m/%d %H:%M’ �Cformat ‘%T %w%f%e’
-e create 被监控目录多个以空格隔开  |while read neirong   ##安装包bin下有相应的执行文件##
do
zhengwen=`echo “$neirong” |grep -a CREATE`
if [ $? = 0 ]
then
#echo “发送邮件”
/usr/local/bin/sendEmail -f 发件人邮箱 -t 收件人邮箱 -s smt
p.exmail.qq.com -u “create” -m “${zhengwen}” -xu 发件人邮箱 -xp 发件人密码
fi
echo “$neirong” >> /root/www-inotify.log
done

给脚本授执行权限

chmod +x 监控脚本

sh 监控脚本 > /dev/null &


你可能感兴趣的:(shell,文件监控)