script to check for a condition inside a file

Hi
I am writing a script file which sends the log files along with their size in a folder named log to a file called temp.log using the following cmd:
ls -st 190_GSTV_HUX_003QISCGSK026** >> /home/user/temp.log

the temp.log looks like this:
16 190_GSTV_HUX_003QISCGSK026_message070321.log
21 190_GSTV_HUX_003QISCGSK026_activity070321.log
10 190_GSTV_HUX_003QISCGSK026_error070321.log

now i need to write a script which checks for the error log file size inside the temp.log
ie., i need to check if the error log file(190_GSTV_HUX_003QISCGSK026_error070321.log) size is zero or not from the file temp.log

is there any cmd to do the same?

any help is greatly appreciated
thanks in advance!!

Hi,

not sure whether I understood your problem properly...You can do something like this if u want to take out size and filename seperately ..

ls -st GSTV_error** >> /home/user/temp.log
cat temp.log | awk -F" " 'NR >1 {print "File "$2 " Size "$1 ;}'

or you can go for

while read line
do
{
file=$(echo $line| cut -f1)
size=$(echo $line| cut -f2)
echo "$file $size"
if [ "$file" = "something" -a $size -eq val ]
then

...do something..

fi
}
done <temp

Ok.Try something like below then...

ls -st >temp
while read line
do
{
file=$(echo $line| cut -f2 -d" ")
size=$(echo $line| cut -f1 -d" ")
if [ "$file" = "190_GSTV_HUX_003QISCGSK026_error070321.log" -a $size -gt 0 ]
then
echo "$file and $size" #or do whatever you want to do with that..
fi
}
done <temp

ls -lst 190_GSTV_HUX_003QISCGSK026** >> /home/user/temp.log

the temp.log looks like...

16 blah blah blah blah size 190_GSTV_HUX_003QISCGSK026_message070321.log
21 blah blah blah blah size 190_GSTV_HUX_003QISCGSK026_activity070321.log
10 blah blah blah blah size 190_GSTV_HUX_003QISCGSK026_error070321.log

sixth column shows size of the file

check=`cat /home/user/temp.log | awk '{print $6}'`

it will show you size of the file....

if [ $check -eq 0 ]
then
echo "do this"
else
echo "do this"
fi

Hi
many thanks for ur quick reply...
i am trying to do this:
ls -st 190_GSTV_HUX** >> /home/gaaadmin/GAAAdapter/gskgaa/test.log
cd ..
check=`awk 'NR == 6 {print $1}' test.log`

if [ $check -eq 0 ]
then
echo "noerror"
else
echo "error present"
fi

but the thing is this condition checks only for the first line in test.log which may or may not be the error log file ...
so my quwstion is how do we get it to check only for the filename which contains error...

hope i m not confusing you
thanks

If you just want to display those files with zero size,
go for this...

awk '{if ($1>0) {print "no errors in "$2; }else{ print "Error in "$2;}} temp.log

Or if you can use the below approch to tackle this..
while read line
do
{
file=$(echo $line| cut -f2 -d" ")
size=$(echo $line| cut -f1 -d" ")
if [ "$file" = "190_GSTV_HUX_003QISCGSK026_error070321.log" -a $size -gt 0 ]
then
echo "$file and $size" #or do whatever you want to do with that..
fi
}
done <temp

Guys, please wrap your code within the code tags for the benefit of everyone.

Thanks Jacoden...
actually my reqirement is not just to display those files with zero size but to check if the error log file is of size zero .
pls note that 190_GSTV_HUX_003QISCGSK026_errorXXXXXX.log(Here XXXXXX changes everytime i run the script..it gives the date time)
so i need to check for the error log file size is zero or not among the following:
16 190_GSTV_HUX_003QISCGSK026_messageXXXXX.log
21 190_GSTV_HUX_003QISCGSK026_activityXXXXX.log
10 190_GSTV_HUX_003QISCGSK026_errorXXXXX.log
The above files can b in any order.....

is there any cmd as such which suits my need

Thanks in advance

How about

sed -n -e "/^ *0 .*/p" /home/user/temp.log

no Vino
no luck with it too...
:frowning:

Let me get this straight. You want all *error*.log files of zero size. Right ?

sed -n -e "/^ *0 .*_error.*/p" /home/user/temp.log

Thanks vino
the cmd which u suggested is listing all the error files of size 0..
but i want to check for the latest error log file size :frowning:

presently i am able to display only first 3 files in test.log by using
head -3 test.log
from these 3 files i need to get the error log file size and write a condition based on its size..........

BTW what do u mean by code tags?where can i find them :confused:
many thanks for your suggestions :slight_smile: