Many times as admins we will be performing activities like Migration/Cutover/Upgrade.
During this activity, we will take backup of several files most likely with words "pre" or "before", prefixed/suffixed in the name of file.
After completion of the activity, needless to say we will have to perform a daunting task of comparing the pre/before files with post/after files. Since there can be numerous files, this can be a heavy cross to bear.
Below snippet can be handy to deal with these situations and I recommend to copy this into a file and execute as shell script.
clear; for fname in `ls -ltr | grep -iE "pre|before" | awk '{print $9}' | awk -F'before|pre' '{print $0}'`
do
echo "Should I continue with comparison of next file?"
echo "Enter 'y' or 'Y' or 'Yes' or 'yes' to continue"
read uip
if [[ $uip == 'y' || $uip == 'Y' || $uip == 'yes' || $uip == 'Yes' ]]; then
echo "Comparing files ${fname}* and `echo ${fname}\* | sed 's/pre/post/g;s/before/after/g'`"
else
echo "Exiting as input not in {'y' or 'Y' or 'Yes' or 'yes'}"
exit
fi
sdiff ${fname}* `echo ${fname}\* | sed 's/pre/post/g;s/before/after/g'`>/dev/null
sdiff_rc=$?
if [[ $sdiff_rc != 0 ]]; then
echo "Below differences are identified while comparing file --- $fname* with `echo ${fname}\\* | sed 's/pre/post/g;s/before/after/g'` ---"
echo "-----------------------------------------------------------------------------------------"
sdiff -s -w 200 $fname* `echo ${fname}\* | sed 's/pre/post/g;s/before/after/g'` |grep -En "<|>"
echo "######--- Execute below command to get detailed comparison ---######"
echo "sdiff $fname* `echo ${fname}\* | sed 's/pre/post/g;s/before/after/g'`"
echo "###"
echo "###"
else
echo "No differences are identified while comparing file --- $fname* with `echo ${fname}\* | sed 's/pre/post/g;s/before/after/g'` ---"
echo "###"
echo "###"
fi
done
PS, include either pre/before in the names of files generated before activity and post/after in the names of files generated after activity.
No comments:
Post a Comment