First time posting here. I keep getting back here on my google searches to help me in my scripting quest.
Can i ask for some guidance please?
I acquired a script, from these forums in fact that pings a list of IPs/Hostnames. Works a treat. Echos results to a file with the value (IP/Hostname) pinged.
Before
device1 1.1.1.1
device2 2.2.2.2
Script
#! /bin/sh
IPLIST=`less ./devices.txt | awk '{print $2}'`
for ip in $IPLIST
do
echo $ip
ping -c 2 $ip >>device-log.txt
if [ $? -eq 0 ]
then
echo $ip "PINGS">>pingresultsace-device.txt
else
echo $ip "DOESN'T PING">>pingresultsace-device.txt
fi
done
The output is
1.1.1.1 PINGS
2.2.2.2 DOESN'T PING
What i would really like is to put the entire line, or parts of it to produce. By parts of it i mean, using the AWK command or similar to select the fields to echo.