检测目录文件变更数量及内容变更
Posted 运维搬砖
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了检测目录文件变更数量及内容变更相关的知识,希望对你有一定的参考价值。
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin/:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
dir=/home/
date_one_h=$(date +%Y%m%d%H -d ‘-1 hours‘)
old_file=/root/$(date +%Y%m%d -d ‘2 day ago‘)source.file
source_file=/root/$(date +%Y%m%d)source.file
new_file=/root/Desktop/$(date +%Y%m%d%H)new.file
change_content=/root/Desktop/$(date +%Y%m%d%H)diff.file
old_change_content=/root/Desktop/$(date +%Y%m%d%H -d ‘2 day ago‘)diff.file
if [ -s $source_file ] ;then
echo the file content alrealy exists!
else
#find $dir -print0 | xargs -0 du -sb >$source_file
ls -lR $dir >$source_file
echo "$source_file File content has been written!"
fi
if [ -s $new_file ] ;then
echo the $new_file content alrealy exists!
else
#find $dir -print0 | xargs -0 du -sb >$new_file
ls -lR $dir >$new_file
echo "$new_file File content has been written!"
fi
diff_input=$(diff $source_file $new_file)
if [[ -z $diff_input ]];then
echo "Nothing change"
else
echo "Here is the change"
echo "$diff_input">$change_content
fi
rm -rf $new_file
rm -rf $old_file
rm -rf $old_change_content
以上是关于检测目录文件变更数量及内容变更的主要内容,如果未能解决你的问题,请参考以下文章