loudmouthman

Inotifywait - init.d script

Jan 11th, 2016
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.24 KB | None | 0 0
  1. #notifywait: Start/Stop inotifywait
  2. #
  3. # chkconfig: - 80 20
  4. # description: inotifywait waits for changes to files using inotify.
  5. #
  6. # processname: inotifywait
  7.  
  8. #. /etc/rc.d/init.d/functions
  9. #. /etc/sysconfig/network
  10. . /etc/inotifywait.conf
  11.  
  12. LOCK=/var/lock/subsys/inotifywait
  13.  
  14. RETVAL=0
  15. start() {
  16.    echo -n $"Starting inotifywait: "
  17.    /usr/bin/inotifywait \
  18.    --recursive \
  19.    --format '%w%f %e %T' \
  20.    --timefmt '%Y/%m/%d-%H:%M:%S' \
  21.    --exclude '.*\.sw[pox].*' \
  22.    -e $EVENT \
  23.    -o $LOGFILE \
  24.    -dmrq $MONITOR
  25.  
  26.    RETVAL=$?
  27.    echo
  28.    [ $RETVAL -eq 0 ] && touch $LOCK
  29.    return $RETVAL
  30. }
  31. stop() {
  32.    echo -n $"Stopping inotifywait: "
  33.    psid=$(/bin/ps aux | /bin/grep -i inotifywait | /bin/grep -e "usr/bin"  | /usr/bin/awk {'print $2'} )
  34.    if [[ $psid > 0 ]]; then
  35.         /bin/kill $psid
  36.    fi
  37.    RETVAL=$?
  38.    echo
  39.    [ $RETVAL -eq 0 ] && rm -f $LOCK
  40.    return $RETVAL
  41. }
  42. case "$1" in
  43.    start)
  44.       start
  45.       ;;
  46.    stop)
  47.       stop
  48.       ;;
  49.       ;;
  50.    status)
  51.       /bin/ps aux | /bin/grep -i inotifywait | /bin/grep -e "usr/bin"  | /usr/bin/awk {'print $2'}
  52.       ;;
  53.    restart)
  54.       stop
  55.       start
  56.       ;;
  57.    *)
  58.       echo $"Usage: $0 {start|stop|status|restart}"
  59.       exit 1
  60. esac
  61. exit $?
Add Comment
Please, Sign In to add comment