What about incron ? It runs commands to modify files / directories.
sudo apt-get install incron
Example:
<path> <mask> <command>
Where <path> can be a directory (this means that the directory and / or files are viewed directly in this directory (not the files in subdirectories of this directory!)) Or the file.
<mask> can be one of the following:
IN_ACCESS File was accessed (read) (*) IN_ATTRIB Metadata changed (permissions, timestamps, extended attributes, etc.) (*) IN_CLOSE_WRITE File opened for writing was closed (*) IN_CLOSE_NOWRITE File not opened for writing was closed (*) IN_CREATE File/directory created in watched directory (*) IN_DELETE File/directory deleted from watched directory (*) IN_DELETE_SELF Watched file/directory was itself deleted IN_MODIFY File was modified (*) IN_MOVE_SELF Watched file/directory was itself moved IN_MOVED_FROM File moved out of watched directory (*) IN_MOVED_TO File moved into watched directory (*) IN_OPEN File was opened (*)
<command> is a command that should be executed when an event occurs. The following substitutions can be used in the command specification:
$$ dollar sign $@ watched filesystem path (see above) $# event-related file name $% event flags (textually) $& event flags (numerically)
If you are looking at a directory, then $ @ contains the directory path and the $ # file that raised the event. If you are watching a file, then $ @ contains the full path to the file, and $ # is empty.
Working example:
$sudo echo spatel > /etc/incron.allow $sudo echo root > /etc/incron.allow
Start daemon:
$sudo /etc/init.d/incrond start
Edit incrontab file
$incrontab -e /home/spatel IN_CLOSE_WRITE touch /tmp/incrontest-$#
Check him
$touch /home/spatel/alpha
Result:
$ls -l /tmp/*alpha* -rw-r--r-- 1 spatel spatel 0 Feb 4 12:32 /tmp/incrontest-alpha
Notes: In Ubuntu you need to activate inotify at boot time. Add the following line to the menu.lst grub file:
kernel /boot/vmlinuz-2.6.26-1-686 root=/dev/sda1 ro inotify=yes
Satish
source share