威尼斯wns.9778官网 > 计算机教程 > 利用shell脚本监控目录内文件改动,

原标题:利用shell脚本监控目录内文件改动,

浏览次数:96 时间:2019-05-11

#! /bin/bash
webroot="/home/www/"
cp /dev/null rsync_file
if [ ! -f   file.md5 ];then
        find $webroot  -type f -exec md5sum {} ; >>file.md5
else
        for file in $(md5sum -c file.md5|awk  -F':' '/FAILED/{print $1}')
                do
                        if [ -f $file ];then
                        filename_z=$(echo $file|sed 's#/#\/#g')
                        sed -i "/  $filename_z/"d   file.md5
                        md5sum $file >> file.md5
                        echo $file >> rsync_file
                        else
                        echo $file >>rsync_rm
                        fi
                done
        for newfile in $(find $webroot  -type f)
                do
                        grep $newfile file.md5 >/dev/null 2>&1
                        if  [ $? -gt 0 ];then
                        md5sum $newfile >> file.md5
                        echo "$newfile" >> rsync_file
                        fi
                done
for rfile in $(cat rsync_file)
do
rsync -avzp $rfile  /home/www3/
done

利用shell脚本监控目录内文件改动,

#! /bin/bash
webroot="/home/www/"
cp /dev/null rsync_file
if [ ! -f   file.md5 ];then
        find $webroot  -type f -exec md5sum {} ; >>file.md5
else
        for file in $(md5sum -c file.md5|awk  -F':' '/FAILED/{print $1}')
                do
                        if [ -f $file ];then
                        filename_z=$(echo $file|sed 's#/#\/#g')
                        sed -i "/  $filename_z/"d   file.md5
                        md5sum $file >> file.md5
                        echo $file >> rsync_file
                        else
                        echo $file >>rsync_rm
                        fi
                done
        for newfile in $(find $webroot  -type f)
                do
                        grep $newfile file.md5 >/dev/null 2>&1
                        if  [ $? -gt 0 ];then
                        md5sum $newfile >> file.md5
                        echo "$newfile" >> rsync_file
                        fi
                done
for rfile in $(cat rsync_file)
do
rsync -avzp $rfile  /home/www3/
done

脚本介绍:

1,监控 /home/www/ 目录改动,并将改动的文件rsync到/home/www3目录

2,监控方法为监控文件的md5值,如果md5值与上次不同,即发生改变

如有问题,请联系:410018348

本文出自 “运维人生” 博客,请务必保留此出处http://yaozb.blog.51cto.com/2762349/1297347

http://www.bkjia.com/Linuxjc/1210987.htmlwww.bkjia.comtruehttp://www.bkjia.com/Linuxjc/1210987.htmlTechArticle利用shell脚本监控目录内文件改动, #! /bin/ bashwebroot = " /home/www/ " cp /dev/ null rsync_file if [ ! -f file .md5 ]; then find $webroot -type f -exec md5sum {} ;...

脚本介绍:

1,监控 /home/www/ 目录改动,并将改动的文件rsync到/home/www3目录

本文由威尼斯wns.9778官网发布于计算机教程,转载请注明出处:利用shell脚本监控目录内文件改动,

关键词:

上一篇:计算机应用基础教程作业 车辆工程 王宏鑫

下一篇:没有了