Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A korn script that will check for number of files (auditing) 1

Status
Not open for further replies.

tijerina

Vendor
Mar 4, 2003
132
US
I would like to have a korn script that would count files in a directory and compare them to a base file. In other words, a script will count files in a certain directory, it will then output what it has counted to a file, this file will then compare this count with another file that has what the exact file should be. This would be an auditing script, that would check multiple directories. Any ideas?

All assistance will be very much appreciated.
 
Try something like:
#!/bin/ksh
auditlog=/logdir/logfile
echo " File count test " > $auditlog
for dirs in /adir /bdir /cdir /ddir
do
basecount=`cat ${dirs}/basefile` #contains no. of files
dircount=`ls ${dirs/*|wc -l`
if [ $dircount -ne $basecount ]
then
echo "Imbalance in $dirs - Count=$dircount - Should be $basecount" >> $auditlog
else
echo "OK in $dirs - Count=$dircount - Same as $basecount" >> $auditlog
fi
done

HTH
Dickie Bird (:)-)))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top