Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- FILE_TO_WATCH="/tmp/ndnproxymain.conf"
- PREVIOUS_HASH=""
- # Commands to execute when the file changes
- COMMANDS_ON_CHANGE="
- ipset flush bypass
- /opt/etc/init.d/S52ipset-dns restart
- "
- # Function to calculate MD5 hash of the file
- calculate_md5() {
- md5sum "$FILE_TO_WATCH" | awk '{ print $1 }'
- }
- # Function to execute commands when the file changes
- on_file_change() {
- eval "$COMMANDS_ON_CHANGE"
- }
- # Function to start the script
- start() {
- echo "Starting ipset watcher..."
- PREVIOUS_HASH=$(calculate_md5)
- inotifywait -q -m -e close_write "$FILE_TO_WATCH" | while read _; do
- CURRENT_HASH=$(calculate_md5)
- if [ "$CURRENT_HASH" != "$PREVIOUS_HASH" ]; then
- PREVIOUS_HASH="$CURRENT_HASH"
- on_file_change
- fi
- done &
- echo $! > /var/run/ipset_watcher.pid
- }
- # Function to stop the script
- stop() {
- echo "Stopping ipset watcher..."
- kill $(cat /var/run/ipset_watcher.pid)
- rm /var/run/ipset_watcher.pid
- }
- case "$1" in
- start)
- start
- ;;
- stop)
- stop
- ;;
- restart)
- stop
- start
- ;;
- *)
- echo "Usage: $0 {start|stop|restart}"
- exit 1
- ;;
- esac
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement