Wednesday, March 2, 2011

BASH script for doing MD5 checksums

Description: 
This script can be used for doing MD5 checksums on files which are copied/downloaded from FTP server or on files which are restored from Backup tapes to ensure the integrity. This script takes Source path as command-line parameter and upon completion it prints the result on the terminal.

Syntax:  
# scripname.sh  <Source path> 


Sample execution:
[root@oralsb11-new ]# /opt/do_checksum.sh /smbnas/oralsb11
MD5 Checksum testing passed for all the files
[root@oralsb11-new ]#

[root@oralsb11-new tmp]# cat capture_success
./dbfile_IHOTPERF_744220566_255_1.rman: OK
./dbfile_IHOTPERF_744220566_256_1.rman: OK
./dbfile_IHOTPERF_744220566_257_1.rman: OK
./dbfile_IHOTPERF_744221122_258_1.rman: OK
./dbfile_IHOTPERF_744221187_259_1.rman: OK
./dbfile_IHOTPERF_744221293_260_1.rman: OK
./dbfile_IHOTPERF_744221578_261_1.rman: OK
./dbfile_IHOTPERF_744221744_262_1.rman: OK
./dbfile_IHOTPERF_744221829_263_1.rman: OK
./dbfile_IHOTPERF_744222035_264_1.rman: OK
./dbfile_IHOTPERF_744222150_265_1.rman: OK
./dbfile_IHOTPERF_744222176_266_1.rman: OK
./dbfile_IHOTPERF_744222501_267_1.rman: OK
./dbfile_IHOTPERF_744222509_268_1.rman: OK
./dbfile_IHOTPERF_744222674_269_1.rman: OK
./dbfile_IHOTPERF_744222959_270_1.rman: OK
./dbfile_IHOTPERF_744223025_271_1.rman: OK
./dbfile_IHOTPERF_744223171_272_1.rman: OK
./initihotperf.ora: OK
./orapwihotperf: OK
[root@oralsb11-new tmp]# cat capture_failure
[root@oralsb11-new tmp]#
__________________________________________________________________
SCRIPT


#!/bin/bash
# Description: This script is for doing MD5 checksum checks on files on Linux server.
SRC_DIR=$1
RESULT_FILE=/tmp/checksums_result.txt
FAILURE=/tmp/capture_failure
SUCCESS=/tmp/capture_success
cd $SRC_DIR
find ./ -type f -exec md5sum {} \; > /tmp/checksums.txt
md5sum -c < /tmp/checksums.txt > $RESULT_FILE
cat $RESULT_FILE |  grep -v " OK$" > $FAILURE
cat $RESULT_FILE |  grep OK > $SUCCESS
rm -rf $RESULT_FILE
cat $FAILURE | grep OK
if [ "$?" != "1" ]; then
echo "Some of the files not passed the MD5 Checksum testing" && echo
cat $FAILURE
exit 0
else
echo "MD5 Checksum testing passed for all the files"
exit 0
fi
__________________________________________________________________

No comments:

Post a Comment

Popular Posts

About Me

My photo
The intent of this blog is to share my work experience and spread some smart solutions on Linux to System Administrators. I'm hoping the solutions shared in this Blog would be helpful and come as a handy for Viewers. Brief about me: I have 18+ years work experience in System and Cloud Administration domain, primarily works on VMware Cloud Products (vSphere, vCloud Director, vRealize Automation, NSX Adv. Load Balancer, vROps).