Linux uses inotify-tools's inotifywait implementation: When the folder content changes, a script is automatically executed. when I create an rpm Package management server, this requirement exists, when a new rpm is stored in a specified directory, a script is automatically executed to check the rpm package. This... linux uses inotify-tools's inotifywait implementation: When the folder content changes, a script is automatically executed. when I create an rpm Package management server, this requirement exists, when a new rpm is stored in a specified directory, a script is automatically executed to check the rpm package. The inotifywait module of inotify-tools is used here. there is an event processing parameter-e, which can be found in its manual. My code is as follows: [python] #/bin/bash ################################ ################################# automatically run a script (action. sh) when the contents # of a directory ($ {EVENTPATH}) changed. # pls. install the inotify-tools-3.13-1.el4.rf.i386.rpm module # before use this scripts # Aborn Jiang (aborn.jiang@gmail.com) # Sep.8, 2013 ####################################### ######################### EV ENTPATH = ". "MSG = ". inotifymsg "PATTERN = ". rpm $ "# only when the rpm files changed. while inotifywait-e modify-e create-e delete-e moved_to-e moved_from \$ {EVENTPATH} 1 >1 {EVENTPATH}/$ {MSG} 2>/dev/null; do FILE = 'cat $ EVENTPATH/$ {MSG} | egrep $ {PATTERN} | awk '{print $3}' 'action = 'cat $ EVENTPATH/$ {MSG} | egrep $ {PATTERN} | awk '{print $2 }''[! -Z $ {FILE}] & \ echo "in the directory $ {EVENTPATH}, the file :$ {FILE} modified, action :$ {ACTION }"&&\. /action. sh done I only want to check whether there is any rpm change here. you can modify the PATTERN variable content in the code to detect any file! If you want to detect any file, you can set PATTERN to "*" and put the execution script in action. sh.
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.