I need some help about how to filter the data returned by a traceroute.
Introduction I'm running a bash script that checks for the IP returned by this command:
IP=`traceroute -m 2 www.test.com | awk -vOFS='\t' '{if (NR==3){print $2}}'`
echo "$IP: `date`"
Based on the value of "$IP" I execute an "expect" command to modify a parameter inside a switch.
The bash script is scheduled via root crontab.
Description of the problem The crontab executing that bash script is generating a log like this
192.168.3.25: vie dic 14 14:10:23 CET 2012
192.168.3.25: vie dic 14 14:20:12 CET 2012
192.168.3.25: vie dic 14 14:30:11 CET 2012
192.168.3.25: vie dic 14 14:40:11 CET 2012
192.168.3.25: vie dic 14 14:50:11 CET 2012
expect /root/Scripts/delete.exp
192.168.3.111: vie dic 14 15:00:11 CET 2012
*: vie dic 14 15:10:11 CET 2012
*: vie dic 14 15:20:16 CET 2012
As you can notice, after execute the expect script there is a problem, and the traceroute line begin to return "*" instead the right IP (192.168.3.25). I think that for some reason after do a modification on the switch, and for around 20 minutes, the traceroute returns one line less (the first line, showing the IP of the switch, is missing).
I've test the value returned for traceroute in several ways, and I think I should avoid to use awk to filter the values returned from traceroute. That's because as long as I know, by using awk I just can use "NR" to filter the line. So, I don't know how I could filter these values in order for search an specific one (i.e, one specific IP).
Thank you for your help.