Question

I am trying to extract the highest number from $countip and copy it to $totalip, the problem is that $totalip is allways returning 0. Can anybody help me please, i am new to bash script.

for srcip in `cat /var/log/messages | grep "WACSLAW1 CRITICAL INCOMING" | awk '{ print $14 }'|grep -v 192.168.1. |grep -v IN=eth1 |grep -v MAC`;do
        if (! grep "$srcip" /var/wacstemp/ids.tmp > /dev/null) ; then
                countip=0
                echo $srcip >> /var/wacstemp/ids.tmp
        else
                countip=`expr $countip + 1`

                        if [ $countip -gt $totalip ];
                        then 
                        #       echo $countip
                                countip=$totalip
                        #       echo $totalip
                        fi
        fi
done
Was it helpful?

Solution

You must switch

countip=$totalip

to

totalip=$countip

otherwise totalip will never be updated.

OT: You could simplify the initial filter to

awk '/WACSLAW1 CRITICAL INCOMING/ && $14 !~ /192.168.1./ && $14 !~ /IN=eth1/ && $14 !~ /MAC/ { print $14 }' /var/log/messages
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top