安装inotify

    1. # 安装inotify
    2. wget --no-check-certificate https://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
    3. tar zxvf inotify-tools-3.14.tar.gz
    4. cd inotify-tools-3.14
    5. ./configure
    6. make
    7. make install

    修改inotify管理的队列的最大长度

    echo 104857600 > /proc/sys/fs/inotify/max_user_watches
    

    监听脚本

    #!/bin/bash
    # 监控的目录
    monitor_path=/home/dir1/
    # 解压的目标目录
    desc_dir=/home/dir2
    inotifywait -m -e close_write $monitor_path --format "%w%f" | while read file
    do
    echo $file
        if [[ $file =~ (.*)\.war$ ]];then
        rm -rf $desc_dir/*
        unzip  $file -d $desc_dir/  &> /dev/null
        t=`date`
        echo $t' '$file'解压完成'
        echo $t' '$file'解压完成' >> log.txt
        echo $t' '$file'解压完成' | mail -s "war包上传提示" xxx@xxxx.com
        fi
    done