I wrote one shell script to check the record count in two files and that will send us the notification activity if found zero record count.
What i did is I created for loop and checking the count for both of the files but what is happening is for first file has data then it's getting exit and not checking another file count.
I have prepared script as below please check it and correct me if anything wrong.
#!/bin/sh
a=/tjx/iisNAS/data/edw/fp/output/common/sample.txt
b=/tjx/iisNAS/data/edw/fp/output/common/sample1.txt
for file in `wc -l $a |awk -F " " '{print $1}'` `wc -l $b |awk -F " " '{print $1}'`
do
if [ $file -eq 0 ];
then
mailx -s " $file Data is not available in lookup"
exit 1
else
mailx -s " $file /tjx/iisNAS/data/edw/fp/output/common/sample.txt Data is available in lookup" abc@yahoo.com
exit 0
fi
Not sure I grasp your logics. Why dont you try like this (untested):
a=/tjx/iisNAS/data/edw/fp/output/common/sample.txt
b=/tjx/iisNAS/data/edw/fp/output/common/sample1.txt
for file in $a $b
do if [ 0 -eq $(wc -l $file) ]
then mailx ...
exit 1
else mailx ...
exit 0
fi
done
Why do you define the a and b variables, use them for the for loop, and then put in the filenames as fixed strings? And what is the && for at the end of the if line?
The reason for your complaint is called "shortcircuit evaluation" and is used in many languages: If the first operand in an and operation fails, the result is known and the second is not needed to be evaluated.
Actually script given by you i executed and checked the result what it is doing checking the first file if data is there then getting executed exit command and coming out.Not checking for another file.
So I have prepared please review and correct me if anything wrong.
Sorry, I don't get the logics behind your request nor from your code snippet. Please explain in plain English what you want to achieve. Are you aware of the short circuit evaluation?
Hi Rudy, I have executed the below script but it's checking the first file and if data found infile then it's getting executed exit 0 and coming out side without check the second file. a=/tjx/iisNAS/data/edw/fp/output/common/sample.txtb=/tjx/iisNAS/data/edw/fp/output/common/sample1.txtfor file in $a $bdo if [ 0 -eq $(wc -l <$file) ] then mailx ... exit 1 else mailx ... exit 0 fidoneCan you please verify and correct me if anything worng.
There may be some of the files which has zero records(Ex:First file has data..second file doesn't have data...) when it checks for first file it's gone through but second file doesn't have data as per my consern second file also has to be checked.
But it's coming out from for loop.