批量检测文件是否改动脚本

版权声明:本文为博主原创文章,未经博主允许不得转载,转载附上原文链接即可。 https://blog.csdn.net/GX_1_11_real/article/details/89676715

前言


下面分享一个批量检测文件改动的脚本。

使用场景:
测试环境下使用旧代码服务正常,而新上线后服务出现异常,用来将新代码的文件的改动排查出来,加快排查进度。
也可用于其他两个目录中文件的对比。



#!/bin/bash


old_dir=/data/back/webapp/webapp_201903/
new_dir=/data/online/webapp/
mdlog=/var/log/md5.log

> $mdlog

find $old_dir -type f |xargs md5sum > /tmp/old_md5.txt
find $new_dir -type f |xargs md5sum > /tmp/new_md5.txt

for i in `awk '{print $2}' /tmp/old_md5.txt`
do   
     grep -q "$i"  /tmp/new_md5.txt 
     if [ $? -eq 0];then        
        md5_1 =`grep $i  /tmp/old_md5.txt |awk '{print $1}'`
        md5_2 =`grep $i  /tmp/new_md5.txt |awk '{print $1}'`
                
        if [ $md5_1 != $md5_2 ];then
             echo "$i  is update" 
             echo "$i  is update"  >> $mdlog
        fi
    else
        echo "$i does not exist"  
         echo "$i does not exist" >> $mdlog
    fi
done  


备注


old_dir为旧代码,new_dir为新代码,该脚本是依据旧代码的文件为基础与新代码进行对比,旧代码的文件多于新代码。因此使用该脚本进行文件对比时,old_dir变量配置的目录的文件数应多于new_dir变量配置的目录的文件数。

建议使用tree命令先对两个目录的文件数进行对比。

格式:tree 目录名

在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/GX_1_11_real/article/details/89676715