관리 메뉴

Sysops Notepad

리눅스 파일시스템 감시 알림 inotify 사용법 본문

업무/sys

리눅스 파일시스템 감시 알림 inotify 사용법

sysops 2018. 11. 26. 11:24

리눅스 파일시스템 감시를 통한 변경,생성,삭제,위치변경 알림 inotify 사용법

OS : centos 7.5



# yum install inotify-tools  


# inotifywait -e create,delete,modify,move -mrq /test & 


# touch /etc/test.txt

/etc/ CREATE test.txt# detected


# vi /etc/inotifywait.conf # create config file


LOGFILE=/var/log/inotify.log


MONITOR=/test


EVENT=create,delete,modify,move



# vi /etc/rc.d/init.d/inotifywait 

----------------------------------------------------------


#!/bin/bash


# inotifywait: Start/Stop inotifywait

#

# chkconfig: - 80 20

# description: inotifywait waits for changes to files using inotify.

#

# processname: inotifywait


. /etc/rc.d/init.d/functions

. /etc/sysconfig/network

. /etc/inotifywait.conf


LOCK=/var/lock/subsys/inotifywait


RETVAL=0

start() {

   echo -n $"Starting inotifywait: "

   /usr/bin/inotifywait \

   --format '%w%f %e %T' \

   --timefmt '%Y/%m/%d-%H:%M:%S' \

   --exclude '.*\.sw[pox].*' \

   -e $EVENT \

   -o $LOGFILE \

   -dmrq $MONITOR


   RETVAL=$?

   echo

   [ $RETVAL -eq 0 ] && touch $LOCK

   return $RETVAL

}

stop() {

   echo -n $"Stopping inotifywait: "

   killproc inotifywait

   RETVAL=$?

   echo

   [ $RETVAL -eq 0 ] && rm -f $LOCK

   return $RETVAL

}

case "$1" in

   start)

      start

      ;;

   stop)

      stop

      ;;

   status)

      status inotifywait

      ;;

   restart)

      stop

      start

      ;;

   *)

      echo $"Usage: $0 {start|stop|status|restart}"

      exit 1

esac

exit $?


----------------------------------------------------------


# chmod 755 /etc/rc.d/init.d/inotifywait 

# /etc/rc.d/init.d/inotifywait start 

# chkconfig --add inotifywait 

# chkconfig inotifywait on



tail /var/log/inotify.log 

Comments