incron?它觸發文件/目錄更改命令。
sudo apt-get install incron
例子:
<path> <mask> <command>
哪裏<path>
可以是一個目錄(直接在該目錄意味着目錄和/或文件(而不是文件在該目錄的子目錄)都看了!)或文件。
<mask>
可以是下列之一:
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>
是在事件發生時應該運行的命令。以下wildards可以將命令規範內使用:
$$ dollar sign
[email protected] watched filesystem path (see above)
$# event-related file name
$% event flags (textually)
$& event flags (numerically)
如果你看一個目錄,然後$ @保存的目錄路徑和$#觸發事件的文件。如果您觀看一個文件,那麼$ @將保存文件的完整路徑,$#爲空。
工作實例:
$sudo echo spatel > /etc/incron.allow
$sudo echo root > /etc/incron.allow
啓動守護程序:
$sudo /etc/init.d/incrond start
編輯incrontab
文件
$incrontab -e
/home/spatel IN_CLOSE_WRITE touch /tmp/incrontest-$#
測試它
$touch /home/spatel/alpha
結果:
$ls -l /tmp/*alpha*
-rw-r--r-- 1 spatel spatel 0 Feb 4 12:32 /tmp/incrontest-alpha
注:在Ubuntu
你需要在啓動時激活的inotify。請在Grub menu.lst文件中添加以下行:
kernel /boot/vmlinuz-2.6.26-1-686 root=/dev/sda1 ro inotify=yes
請注意。該腳本可以在應用程序完成寫入文件之前運行,並且會壓縮不完整的文件。 – Barmar