Inotify Real-Time Linux File System event monitoring

Source: Internet
Author: User
Tags inotify

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.