I will admit I am a newbie but I am trying to write some simple scripts
Situation:
I have a list of IP Addresses that I want to once or 2 times a day store the average ping response time in a database (mysql) I am part way there but not all the way there
I have the following
cat ./slow | while read line
do
for i in $line
do
ping -c1 -q $i | grep "mdev" | gawk -F"/" '{print $5}'
done
done
Which parses the average response time out properly I really would like to have something like the following
But my Question is Why can I not get $i to show up? in the print statment
cat ./slow | while read line
do
for i in $line
do
ping -c1 -q $i | grep "mdev" | gawk -F"/" '{print "update table set field1 ="$5" where field2="$i""}'
done
done
Results
update table set field1 =138.668 where field2=rtt min/avg/max/mdev = 138.668/138.668/138.668/0.000 ms
update table set field1 =209.089 where field2=rtt min/avg/max/mdev = 209.089/209.089/209.089/0.000 ms
Hea I might have found the issue. I have one SLIGHT problem now
update stores_new set Current_Ping="$5" I cant seem to get the "$5" to be enclosed by a 'value' where mysql will take it
#!/bin/sh
rm /tmp/baseline
/usr/bin/mysql -htxdf -uxxxx -pxxxx -D test1 -e "select Remote_Router_Ethernet_IP_Address from stores_new where Open_or_Closed='Open' and Location_Type !='MSC'" > /tmp/baseline
cat /tmp/baseline | while read line
do
for i in $line
do
ping -c1 -q $i | grep "mdev" | gawk -F"/" '{print "update stores_new set Current_Ping="$5" where Remote_Router_Ethernet_IP_Address='$i';update stores_new set Ping_Diff=(Ping_Current-Ping_Avg) where Remote_Router_Ethernet_IP_Address='$i'; "}' >> /tmp/current_times
done
done
You can use printf to format string a little better. I don't fully understand your SQL, ( eg Ping_Current-Ping_Avg are the fields?) but you get the idea:
gawk -F"/" '
{printf( "update stores_new
set Current_Ping='%s'
where
Remote_Router_Ethernet_IP_Address='$i';", $5);
printf( " update stores_new
set Ping_Diff=(%f )
where
Remote_Router_Ethernet_IP_Address='$i';", Ping_Current-Ping_Avg);} '
and PLEASE use code tags