Im trying to get all ip address from file called ipserver.txt and check if the ip address is down or up. In the file ipserver.txt I have ip address that looks like this:
# My text file ipserver.txt
host1 10.0.0.1
host2 192.168.10.23
host3 192.168.0.1
host4 192.168.23.10
# My script
date
cat ipserver.txt | while read output
do
ping -c 1 "$output" > /dev/null
if [ $? -eq 0 ]
then
# echo -e "\n\033[4;31mHOSTNAME\033[0m \t\t\033[1;4;31mIP\033[0m"
echo "$output is up"
# printf $output >> resultat
else
echo "$output is down"
fi
done
# cat resultat
What Im trying to output is a table of all ouputs like this:
HOSTNAME IP UP/DOWN
--------------------------------------------
host1 10.0.0.1 UP
host2 192.168.10.23 DOWN
host3 192.168.0.1 UP
host4 192.168.23.10 DOWN
--------------------------------------------
In my script Im trying to redirect the $output to resultat, but dont now if Im thinking right. In text file ipserver.txt I can check the ip address from the file if I dont write host1, host2, host3 and host4. Can somebody give me a tip on how to resolve my script, so I can get the output that i want