Shell脚本监控目录内文件改动
废话不多说了,直接给大家贴代码,具体代码如下所示:
#!/bin/bash
webroot="/home/www/"
cp/dev/nullrsync_file
if[!-ffile.md5];then
find$webroot-typef-execmd5sum{}\;>>file.md5
else
forfilein$(md5sum-cfile.md5|awk-F':''/FAILED/{print$1}')
do
if[-f$file];then
filename_z=$(echo$file|sed's#/#\\/#g')
sed-i"/$filename_z/"dfile.md5
md5sum$file>>file.md5
echo$file>>rsync_file
else
echo$file>>rsync_rm
fi
done
fornewfilein$(find$webroot-typef)
do
grep$newfilefile.md5>/dev/null2>&1
if[$?-gt0];then
md5sum$newfile>>file.md5
echo"$newfile">>rsync_file
fi
done
forrfilein$(catrsync_file)
do
rsync-avzp$rfile/home/www3/
done
脚本介绍:
1,监控/home/www/目录改动,并将改动的文件rsync到/home/www3目录
2,监控方法为监控文件的md5值,如果md5值与上次不同,即发生改变
以上所述是小编给大家介绍的Shell脚本监控目录内文件改动,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!