I have wasted one working day writing this scripts.
It compares two folders and make a good tabbed report about their differences.
#!/bin/bash
function DRAW_DEPTH () {
ROUND=$1
while [ $ROUND -ge 0 ]
do
printf %s " "
ROUND=`expr $ROUND - 1`
done
printf %s "|- "
}
function MAIN () {
TAB=`DRAW_DEPTH $DEPTH`
DIR_LIST=`ls -l $1 | awk '{print $9}'`
for i in $DIR_LIST
do
# Si es un directorio entonces vamos por aki
if [ -d ${1}/${i} ]; then
if [ -d ${2}/${i} ]; then
echo "$TAB (OK) ${1}/${i} is a directory, it exist in ${2}"
DEPTH=`expr $DEPTH + 1`
MAIN ${1}/${i} ${2}/${i}
DEPTH=`expr $DEPTH - 1`
TAB=`DRAW_DEPTH $DEPTH`
else
echo "$TAB (**) ${1}/${i} is a directory, it does NOT exist in ${2}"
fi
else
# Si no es un directorio miramos primero si es un LINK
if [ -h ${1}/${i} ]; then
if [ -h ${2}/${i} ]; then
checksum_1=`sum ${1}/${i} | awk '{print $1}'`
checksum_2=`sum ${2}/${i} | awk '{print $1}'`
if [ $checksum_1 == $checksum_2 ]; then
echo "$TAB (OK) $i exists as LINK in $1 and in $2 and they're EQUAL"
else
echo "$TAB (@@) $i exists as LINK in $1 and in $2 but they DIFFER"
fi
else
echo "$TAB (**) $i exists as LINK in $1 but does NOT exist in $2"
fi
else
if [ -e ${2}/${i} ]; then
checksum_1=`sum ${1}/${i} | awk '{print $1}'`
checksum_2=`sum ${2}/${i} | awk '{print $1}'`
if [ $checksum_1 == $checksum_2 ]; then
echo "$TAB (OK) $i exists in $1 and in $2 and they're EQUAL"
else
echo "$TAB (@@) $i exists in $1 and in $2 but they DIFFER"
fi
else
echo "$TAB (**) $i exists in $1 but does NOT exist in $2"
fi
fi
fi
done;
}
DEPTH=-1
MAIN $1 $2
I wrote it while i was working with my RedHat 4-6 with bash interpreter:
GNU bash, version 3.00.15(1)-release (x86_64-redhat-linux-gnu)
But here at work i have Ubuntu 8-04 and bash:
GNU bash, version 3.2.39(1)-release (i486-pc-linux-gnu)
And it doesnt run......... someone can tell about what commands have changed or perhaps another problem.