inotify

#!/bin/bash
#ver 1.2 by gavin
#need inotify-tools.x86_64 && inotify-tools-devel.x86_64 package
#yum -y install inotify-tools.x86_64 inotify-tools-devel.x86_64
 
usage_info () {
    echo "Usage: $0 optstring parameters"
    echo "      --verbose       increase verbosity info"
}
 
install_package () {
    echo "need inotify-tools.x86_64 && inotify-tools-devel.x86_64 package"
    echo ""
    echo "rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt"
    echo "rpm -Uvh http://apt.sw.be/redhat/el5/en/i386/RPMS.dag/rpmforge-release-0.3.6-1.el5.rf.i386.rpm"
    echo "rpm -Uvh http://apt.sw.be/redhat/el5/en/x86_64/RPMS.dag/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm"
    echo "yum -y install inotify-tools.x86_64 inotify-tools-devel.x86_64"
    echo ""
}
 
MONITOR_DIR=/home/atlantis/monitor
LOG_DIR=/home/atlantis/logs
LOG_FILE=$LOG_DIR/monitor.log
#TRANS_DIR=/hdfs2
EVENTS=(-e CREATE,MODIFY,MOVED_TO,DELETE)
PID=/tmp/monitor_file.pid
 
check () {
if [ ! -d $MONITOR_DIR ]
then
  mkdir -p $MONITOR_DIR
fi
 
if [ ! -d $LOG_DIR ]
then
  mkdir -p $LOG_DIR
fi
echo $EOF > $LOG_FILE
}
 
monitor_file () {
while inotifywait ${EVENTS[@]} $MONITOR_DIR; do
    HOST=`ls -rt $MONITOR_DIR |tail -n1`
#    DIR=`cat $MONITOR_DIR/$HOST`
    echo "<-- active ftp get $HOST log files `date +%Y%m%d%H%M%S`-->"
#    echo "`dirname %0`/get_log.sh $HOST"
    /home/atlantis/scripts/get_log.sh $HOST &
    echo ""
done
}
 
main () {
check
[ ! -x /usr/bin/inotifywait ] && install_package
 
[ -e $PID ] && ps -ef |awk '{print $2}' |grep `cat $PID`|grep -v grep &>/dev/null
if [ `echo $?` -eq 0 ]
then
    echo "$0 can not run : process is already running in `cat $PID` pid"
    exit 1
fi
 
if [ $# -eq 0 ]
then
    monitor_file &> $LOG_FILE &
    echo $! > $PID
elif [ "$1" ==  "--verbose" ]
then
    monitor_file
else
    usage_info
    exit 1
fi
}
 
#monitor_file
main $@
 
exit 0
/var/lib/openshift/bccd8eac1968476490eaee9ced33c7bf/app-root/runtime/repo/php/data/pages/inotify.txt · 最后更改: 2012/09/07 09:21 (外部编辑)
到顶部
CC Attribution-Noncommercial-Share Alike 3.0 Unported
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0