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!!
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
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...
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
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.....
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
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
many thanks for your suggestions