I woul like to create a script in order to make a ping to a server and save in a variable a 1 if respond or a 0 if it doesnt. Then with that I could make a graffic of the server, for how long it is up.
So far I have this:
if [ "ping -c xxx.xxx.xxx.xxx" == "64 bytes from" ];
then
#if the ip respond the ping shows online
echo "online!"
else
#if the ip doesnt respond the ping shows offline
echo "offline!"
Can anyone help me with this?:wall:
ping xx.xxx.xxx > /dev/null 2>&1 && echo "ok" || echo "not ok"
# or
ping xx.xxx.xxx > /dev/null 2>&1 && echo "1" || echo "0"
The second form gives you a 1 or a zero.
Thank you,
It is working now, but can you help me with one more thing?
I would like not to type the ip address that I want to make a ping. Instead I want to have a list of ip address in a text with different names like
ad1: xxx.xxx.xxx.xxx
ad2: xxx.xxx.xxx.xxx
and the program responds an echo of ad1 is responding.
How can I make the script to read like that from another log.
thank you:b:
while read LINE
do
ping -c "$LINE" ....
done < ipaddresses