shell - 对比两个文件的MD5值的函数

#!/bin/bash

LOG_PATH="/var/log/my.log"
echo "[LOG] LOG_PATH: $LOG_PATH" >> $LOG_PATH

compareMD5() {
#    echo "In compareMD5 ---"
    file1="$1"
    file2="$2"
#    echo "file1 = $file1"  >> $LOG_PATH

    md5_1=$(md5sum "$file1" | awk '{print $1}')
    md5_2=$(md5sum "$file2" | awk '{print $1}')
#    echo "md5_1 = $md5_1, md5_2 = $md5_2"   >> $LOG_PATH

    if [ "$md5_1" = "$md5_2" ]; then
        echo "[LOG] MD5 values are the same: $file1 | $file2" >> $LOG_PATH
    else
        echo "[LOG] MD5 values are different: $file1 | $file2" >> $LOG_PATH
        echo "[LOG] Exit With ERROR!" >> $LOG_PATH
	    exit 1
    fi
}


compareMD5 /root/file1 /root/file2

你可能感兴趣的:(shell,服务器,linux,运维,shell)