os:linux:file_watcher_service
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
os:linux:file_watcher_service [2020-12-05 00:49] – created Manuel Frei | os:linux:file_watcher_service [2020-12-05 11:30] (current) – Manuel Frei | ||
---|---|---|---|
Line 16: | Line 16: | ||
# | # | ||
file_name="/ | file_name="/ | ||
- | log_file="/ | + | log_file="/ |
+ | lock_file="/ | ||
+ | |||
+ | # check & set lock | ||
+ | exec 200> | ||
+ | flock -n 200 || { echo " | ||
+ | PID=$$ | ||
+ | echo ${PID} 1>& | ||
+ | |||
+ | # file watch | ||
while true; do | while true; do | ||
inotifywait -e modify ${file_name} | inotifywait -e modify ${file_name} | ||
echo " | echo " | ||
- | # maybe do some other actions | + | # maybe do some other actions |
done | done | ||
</ | </ | ||
Line 49: | Line 58: | ||
systemctl daemon-reload | systemctl daemon-reload | ||
systemctl start file_watcher.service | systemctl start file_watcher.service | ||
+ | </ | ||
+ | |||
+ | If you need to create some form of monitoring script/ | ||
+ | < | ||
+ | [root@server ~]# systemctl is-active file_watcher.service >/ | ||
+ | OK | ||
+ | [root@server ~]# systemctl stop file_watcher.service | ||
+ | [root@server ~]# systemctl is-active file_watcher.service >/ | ||
+ | NOK | ||
</ | </ |
os/linux/file_watcher_service.1607125743.txt.gz · Last modified: 2020-12-05 00:49 by Manuel Frei