keepalived: notifyFile_3.sh

File notifyFile_3.sh, 781 bytes (added by krit, 2 years ago)
Line 
1#!/bin/sh
2
3file_removed() {
4    xmessage "$2 was removed from $1" &
5}
6
7file_modified() {
8    TIMESTAMP=`date`
9    echo "[$TIMESTAMP]: The file $1$2 was modified" >> /tmp/monitor_log
10    # root run command unison with env in /home/ubuntu/.unison/default.prf as an ubuntu user
11    su -c "/usr/bin/unison" ubuntu
12}
13
14file_created() {
15    TIMESTAMP=`date`
16    echo "[$TIMESTAMP]: The file $1$2 was created" >> /tmp/monitor_log
17}
18
19inotifywait -q -m -r -e modify,delete,create $1 | while read DIRECTORY EVENT FILE; do
20    case $EVENT in
21        MODIFY*)
22            file_modified "$DIRECTORY" "$FILE"
23            ;;
24        CREATE*)
25            file_created "$DIRECTORY" "$FILE"
26            ;;
27        DELETE*)
28            file_removed "$DIRECTORY" "$FILE"
29            ;;
30    esac
31done