Hello,
I've written a ksh awk script to ping multiple servers and write the results to a file. That part is working ok. I then want to extract the names of only the server which are available. This is indicated by '1 packets received'. The server name actually appears above that line so I found a command that finds source data and prints the line above as well.
Anyway to cut a long story short the script is only finding the first available server and not the rest. My source file looks like:
--- serv001 ping statistics ---
1 packets transmitted, 0 packets received, 100% packet loss PING serv001 (xx.xx.xxx.xx): 56 data bytes
--- serv002 ping statistics ---
1 packets transmitted, 0 packets received, 100% packet loss PING serv002 (xx.xx.xxx.xx): 56 data bytes
64 bytes from xx.x.xx.xx: icmp_seq=0 ttl=254 time=0 ms
--- serv003 ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss round-trip min/avg/max = 0/0/0 ms PING server003 (xxx.xx.xxx.xx): 56 data bytes
--- server004 ping statistics ---
1 packets transmitted, 0 packets received, 100% packet loss PING server004 (xx.xx.xxx.x): 56 data bytes
--- server005 ping statistics ---
1 packets transmitted, 0 packets received, 100% packet loss PING
server005 (xx.xx.x.xx): 56 data bytes
--- server006 ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss round-trip min/avg/max = 0/0/0 ms PING server006 (xx.xx.xx.xx): 56 data bytes
the code is:
cat pingy99 | awk 'NR==1{str=$0}$0~/1 packets received,/{ print str,$0}'>p77
echo The following servers are available:
cat p77
but this only shows the first server found (server3)
Sorry for such a long post but I suppose the bottom line question is:
How do I get the awk to read and report on the entire source file?
Any help appreciated