-1

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
Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
gomesg
  • 243
  • 1
  • 2
  • 4

1 Answers1

0

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
Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
  • This way what happens is that $totalip will retrive me the sum of all ip addresses in /var/log/messages, what i need is how many times an ip is on /var/log/messages. – gomesg Feb 26 '13 at 19:08