inotify 实时的Linux文件系统事件监控
生活随笔
收集整理的這篇文章主要介紹了
inotify 实时的Linux文件系统事件监控
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
標(biāo)簽:inotifywait原創(chuàng)作品,允許轉(zhuǎn)載,轉(zhuǎn)載時請務(wù)必以超鏈接形式標(biāo)明文章 原始出處 、作者信息和本聲明。否則將追究法律責(zé)任。http://cqfish.blog.51cto.com/622299/1065062使用inotify-tools 工具實時監(jiān)控系統(tǒng)事件監(jiān)控inotify-toolshttp://linux.die.net/man/1/inotifywaitinotify-tools 下載地址# wget http://downloads.sourceforge.net/project/inotify-tools/inotify-tools/3.13/inotify-tools-3.13.tar.gz監(jiān)控腳本:# cat file_file_inotifywait.sh#!/bin/sh
inotifywait=/usr/local/bin/inotifywait
monitor_dir=/opt/web/$inotifywait -mr \
? ? ? ?-e create,move,delete,modify \
? ? ? ?--timefmt '%Y-%m-%d %H:%M' \
? ? ? ?--format '%T %e %w%f ' \
? ? ? ?--exclude upload \
? ? ? ?$monitor_dir > /var/log/file_list -e create,move,delete,modify 監(jiān)控系統(tǒng)事件:創(chuàng)建,移動,刪除,修改--exclude upload 排除upload目錄事件監(jiān)控日志 /var/log/file_list2012-11-16 09:08 CREATE /opt/web/test.php
2012-11-16 09:08 MODIFY /opt/web/sord.html可以詳細(xì)查看什么時間文件創(chuàng)建,或者修改了文件。可根據(jù)實際情況,將非系統(tǒng)創(chuàng)建文件自動刪除刪除腳本如下:# cat file_del.sh#!/bin/sh
file_list=/var/log/file_list
del_file_list=/var/log/del_file_list
while [ true ]
do
? ? ? ?grep CREATE $file_list > $del_file_list
? ? ? ?while read file
? ? ? ?do
? ? ? ? ? ? ? ?del=`echo "$file" | awk '{print $4}'`
? ? ? ? ? ? ? ?if [ -f $del ];then
? ? ? ? ? ? ? ? ? ? ? ?rm -f $del
? ? ? ? ? ? ? ?fi
? ? ? ?done<$del_file_list
sleep 10
done# 執(zhí)行 ./file_del.sh & 后臺執(zhí)行
inotifywait=/usr/local/bin/inotifywait
monitor_dir=/opt/web/$inotifywait -mr \
? ? ? ?-e create,move,delete,modify \
? ? ? ?--timefmt '%Y-%m-%d %H:%M' \
? ? ? ?--format '%T %e %w%f ' \
? ? ? ?--exclude upload \
? ? ? ?$monitor_dir > /var/log/file_list -e create,move,delete,modify 監(jiān)控系統(tǒng)事件:創(chuàng)建,移動,刪除,修改--exclude upload 排除upload目錄事件監(jiān)控日志 /var/log/file_list2012-11-16 09:08 CREATE /opt/web/test.php
2012-11-16 09:08 MODIFY /opt/web/sord.html可以詳細(xì)查看什么時間文件創(chuàng)建,或者修改了文件。可根據(jù)實際情況,將非系統(tǒng)創(chuàng)建文件自動刪除刪除腳本如下:# cat file_del.sh#!/bin/sh
file_list=/var/log/file_list
del_file_list=/var/log/del_file_list
while [ true ]
do
? ? ? ?grep CREATE $file_list > $del_file_list
? ? ? ?while read file
? ? ? ?do
? ? ? ? ? ? ? ?del=`echo "$file" | awk '{print $4}'`
? ? ? ? ? ? ? ?if [ -f $del ];then
? ? ? ? ? ? ? ? ? ? ? ?rm -f $del
? ? ? ? ? ? ? ?fi
? ? ? ?done<$del_file_list
sleep 10
done# 執(zhí)行 ./file_del.sh & 后臺執(zhí)行
轉(zhuǎn)載于:https://blog.51cto.com/liyanxin/1342725
總結(jié)
以上是生活随笔為你收集整理的inotify 实时的Linux文件系统事件监控的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Win7如何快速打开命令提示符
- 下一篇: 淘宝IP地址查询