首页 > 代码库 > 检测目录文件变更数量及内容变更
检测目录文件变更数量及内容变更
#!/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
检测目录文件变更数量及内容变更