Use inotify-tools to monitor system events in real time
Inotify-tools
Http://linux.die.net/man/1/inotifywait
Inotify-tools
# Wget http://downloads.sourceforge.net/project/inotify-tools/inotify-tools/3.13/inotify-tools-3.13.tar.gz
Monitoring script:
# 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 monitoring system events: create, move, delete, modify
-- Exclude upload: exclude the upload directory
Event monitoring log/var/log/file_list
CREATE/opt/web/test. php
MODIFY/opt/web/sord.html
You can view the time when the file was created or modified.
Automatically delete non-system files based on actual conditions.
The delete script is as follows:
# 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
# Execution./file_del.sh & background execution
Recommended reading:
Monitor host files and directories using inotifywait
Using inotify + rsync for Linux File batch update
Inotify-tools + rsync real-time file synchronization installation and configuration