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!

Please Help with this Korn Scipt.

Status
Not open for further replies.

tijerina

Vendor
Mar 4, 2003
132
US
Goal:
I want to create a script that will verify the file count and the file names against a static base file.

I will have a static basefile that will have Multiple Dir Names, Names of files in those multiple Directories, and a count of all files in the multiple dirs. The script that I need help with will use this static basefile for comparison.

I would like to have a script that will verify all files in there specfic dirs are present by using this static basefile. I would like the script to create an output that will name the file that is missing and the number of files. Will be dealing with about 15 different directories within the Basefile. I am not sure how to creat the base file either. We have a machine here that has all our third party stuff on it and it is dev machine that we can do an "ls /DIR/*/* | wc -l >> basefile" but all this gives me is a word count. How do I get the name of the file and the number only in the output?

This is what MR. Dickie has helped out with, he is a great member of this site. A wonderful contributor.

#!/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
 
Well, doing it just by a count of how many files are in each directory does NOT check that the files you want to verify are there. It only checks that there is the same number of files in each directory. I would do the following.

First create a file that has one line for each file you want to confirm. For the example I'll call it [tt]filelist.txt[/tt]. It looks kind of like...
[tt]
/adir/subdir1/fileaaa.dat
/adir/subdir2/fileaab.dat
/bdir/filexxx.txt
/cdir/subdir1/fileabc.dat
/cdir/subdir1/fileabd.dat
[/tt]
...and so on, so there is one line per file. Then, you can check them with something like...
[tt]
#!/bin/ksh

FILELIST=filelist.txt

typeset -i MISSING=0
typeset -i FOUND=0
typeset -i TOTAL=0

while read FNAME
do
if [[ ! -f ${FNAME} ]]
then
print -u2 "ERROR: File Missing: ${FNAME}"
(( MISSING += 1 ))
else
(( FOUND += 1 ))
fi
(( TOTAL += 1 ))
done < ${FILELIST}

if (( ${MISSING} ))
then
print -u2 &quot;Of the ${TOTAL} files expected, ${MISSING} were missing!&quot;
else
print &quot;All ${TOTAL} files were found!&quot;
fi
[/tt]
This will explicitly check for the existence of each file and report the ones not found.

To start creating your [tt]filelist.txt[/tt] file, you could do something like...
[tt]
find /adir /bdir /cdir -type f -print > filelist.txt
[/tt]
...then edit it down to just the files you need.

Hope this helps.

 
Thank you SamBones,

For some reason this is not working, within your script, how am I actually verifying what is on the current system I am running this script on. I first need to find out what is on the system and then get those results and run it against the base file.

Can you assist further, please?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top