centos监控web目录www下的文件是否被黑、挂马的脚本
、检查是否有安装inotify
rpm -qa inotify-tools
2、没有先安装epol源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
3、安装
yum install inotify-tools -y
4、脚本
#!/bin/bash CHECKDIR="/root/test" #监控目录路径 LOG="/root/tmp/inot.log" #日志存放路径 function CheckDir { inotifywait -mrq --timefmt ‘%y-%m-%d %H:%M‘ --format ‘%T %f %e‘ -e ‘create,delete,modify,moved_to‘ $CHECKDIR|while read event do INO_TIME=$(echo $event | awk ‘{print $1,$2}‘) # 把inotify输出切割 把时间部分赋值给INO_TIME INO_FILE=$(echo $event | awk ‘{print $3}‘) # 把inotify输出切割 把文件路径部分赋值给INO_FILE INO_EVENT=$(echo $event | awk ‘{print $4}‘) # 把inotify输出切割 把事件类型部分赋值给INO_EVENT if [[ $INO_EVENT = ‘CREATE‘ ]] && [[ $INO_FILE != .* ]];then # 判断事件类型(create) echo "`date ‘+%Y-%m-%d %H:%M‘` create file: $INO_FILE" >> $LOG elif [[ $INO_EVENT = ‘CREATE,ISDIR‘ ]];then echo "`date ‘+%Y-%m-%d %H:%M‘` create dir: $INO_FILE" >> $LOG fi if [[ $INO_EVENT = ‘DELETE‘ ]] && [[ $INO_FILE != .* ]];then # 判断事件类型(delete) echo "`date ‘+%Y-%m-%d %H:%M‘` delete file: $INO_FILE" >> $LOG elif [[ $INO_EVENT = ‘DELETE,ISDIR‘ ]];then echo "`date ‘+%Y-%m-%d %H:%M‘` delete dir: $INO_FILE" >> $LOG fi if [[ $INO_EVENT = ‘MODIFY‘ ]] && [[ $INO_FILE != .* ]];then # 判断事件类型(modify) echo "`date ‘+%Y-%m-%d %H:%M‘` modify file: $INO_FILE" >> $LOG fi done } CheckDir
5、运行脚本
1)测试: ./monitor.sh
2) 后台运行 nohup ./monitor.sh
相关推荐
changecan 2020-11-19
ECSHOP专属建设 2020-11-13
88427810 2020-11-02
步知道 2020-10-27
Junzizhiai 2020-10-10
jackalwb 2020-10-05
小网管 2020-09-03
shiwenqiang 2020-09-14
85251846 2020-09-14
summerinsist 2020-08-21
87901735 2020-08-19
PinkBean 2020-08-11
85407718 2020-08-09
MichelinMessi 2020-07-30
suosuo 2020-07-28
CARBON 2020-07-28
lizhengfa 2020-07-27
88427810 2020-07-26