I had to write a sript that read in a file that contained the results of a directory listing to check if the file name existed in a different directory and if it did, did it have the correct permissions, owner and group.
When you do a read each column group of data becomes a field
Here's a short example of what I did:
Hope it helps
ls -l $testsrc > $workdir/$testsrc
ls -l $devsrc > $workdir/$devsrc
ls -l $prodsrc > $workdir/$prodsrc
while read a b c d e f g h i
do
if test "$i" = ' '
then
continue
fi
if [ -a $prodsrc/$i ]
then
echo 'do nothing' > $workdir/junklog
else
continue
fi
if test "$c" = 'root'
then
echo 'do nothing' > $workdir/junklog
else
echo 'In prod source file' "$i" ' is not owned by root' >> $workdir/scriptlog
fi
if test "$d" = 'root'
then
echo 'do nothing' > $workdir/junklog
else
echo 'In prod source file' "$i" 'does not belong to group root' >> $workdir/scriptlog
fi
if test "$a" = '-rw-r--r--'
then
echo 'do nothing' > $workdir/junklog
else
if test "$a" = 'd*********'
then
echo 'do nothing' > $workdir/junklog
else
echo 'In prod source file' "$i" 'has the wrong permissions' >> $workdir/scriptlog
fi
fi
if [ -d $prodsrc/$i ]
then
if [ -d $testsrc/$i ]
then
continue
else
echo 'directory ' "$i" 'does not exist in testsrc' >> $workdir/scriptlog
continue
fi
fi
if [ -f $testsrc/$i ]
then
cp /dev/null $workdir/findlog
find $prodsrc/$i -newer $testsrc/$i > $workdir/findlog
if [ -s $workdir/findlog ]
then
echo 'file ' "$prodsrc/$i" ' is newer than ' "$testsrc/$i" >> $workdir/scriptlog
rm $workdir/findlog
else
rm $workdir/findlog
else
cp /dev/null $workdir/findlog
find $testsrc/$i -newer $prodsrc/$i > $workdir/findlog
if [ -s $workdir/findlog ]
then
echo 'file ' "$testsrc/$i" ' is newer than ' "$prodsrc/$i" >> $workdir/scriptlog
rm $workdir/findlog
fi
fi
cp /dev/null $workdir/findlog
diff $prodsrc/$i $testsrc/$i > $workdir/findlog
if [ -s $workdir/findlog ]
then
echo 'files ' "$prodsrc/$i" ' do not match ' "$testsrc/$i" >> $workdir/scriptlog
fi
else
echo 'file ' "$i" 'does not exist in testsrc' >> $workdir/scriptlog
fi
###NOW COMPARE PROD SOURCE TO DEV SOURCE
if [ -d $prodsrc/$i ]
then
if [ -d $devsrc/$i ]
then
continue
else
echo 'prod source directory ' "$i" 'does not exist in devsrc' >> $workdir/scriptlog
continue
fi
fi
if [ -f $devsrc/$i ]
then
cp /dev/null $workdir/findlog
find $prodsrc/$i -newer $devsrc/$i > $workdir/findlog
if [ -s $workdir/findlog ]
then
echo 'file ' "$prodsrc/$i" ' is newer than ' "$devsrc/$i" >> $workdir/scriptlog
rm $workdir/findlog
else
cp /dev/null $workdir/findlog
else
cp /dev/null $workdir/findlog
find $devsrc/$i -newer $prodsrc/$i > $workdir/findlog
if [ -s $workdir/findlog ]
then
echo 'file ' "$devsrc/$i" ' is newer than ' "$prodsrc/$i" >> $workdir/scriptlog
rm $workdir/findlog
fi
fi
cp /dev/null $workdir/findlog
diff $prodsrc/$i $devsrc/$i > $workdir/findlog
if [ -s $workdir/findlog ]
then
echo 'files ' "$prodsrc/$i" ' do not match ' "$devsrc/$i" >> $workdir/scriptlog
fi
else
echo 'prod source file ' "$i" 'does not exist in devsrc' >> $workdir/scriptlog
fi
done < $workdir/prodsrc