Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7402331
  • 博文数量: 1756
  • 博客积分: 18684
  • 博客等级: 上将
  • 技术积分: 16232
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-02 10:28
个人简介

啥也没写

文章分类

全部博文(1756)

文章存档

2024年(2)

2023年(44)

2022年(39)

2021年(46)

2020年(43)

2019年(27)

2018年(44)

2017年(50)

2016年(47)

2015年(15)

2014年(21)

2013年(43)

2012年(143)

2011年(228)

2010年(263)

2009年(384)

2008年(246)

2007年(30)

2006年(38)

2005年(2)

2004年(1)

分类: LINUX

2009-12-22 15:09:23

#!/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 "
    echo "rpm -Uvh
.i386.rpm"
    echo "rpm -Uvh .
rf.x86_64.rpm"
    echo "yum -y install inotify-tools.x86_64 inotify-tools-devel.x86_64"
    echo ""
}
 
SOR_DIR=/targeting/data
EVENTS=(-e CREATE,MODIFY,MOVED_TO,DELETE)
TARGET_FILE=word_targeting_mobile.db
PID=/tmp/monitor_file.pid
 
monitor_file () {
while inotifywait ${EVENTS[@]} --exclude word_targeting_mobile.db $SOR_DIR; do
    ls -rt $SOR_DIR |grep -v $TARGET_FILE|tail -n1
    ino_file=$SOR_DIR/`ls -rt $SOR_DIR|grep -v $TARGET_FILE |tail -n1`
    echo $ino_file
    echo "get a new file"
    rm -rf $SOR_DIR/$TARGET_FILE
    ln -s $ino_file $SOR_DIR/$TARGET_FILE
    echo "ln -s $ino_file -> $SOR_DIR/$TARGET_FILE"
done
}
 
main () {
[ ! -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 &>/dev/null &
    echo $! > $PID
elif [ "$1" ==  "--verbose" ]
then
    monitor_file 
else
    usage_info
    exit 1
fi
}
 
main $@
 
exit 0
阅读(1149) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~