Ping script witch up or down status

Viewed 25

Wy dosent work? I'm learning bash scripting but this ping operation dosent work i dont know wy, some one can give me a light please?

#!/bin/bash
r1="<UP>!"
r2="<DOWN>!"
if ! ping -c 1 0.0.0.0
then
echo $r1
else
echo $r2 
fi
1 Answers

You are using "!" which negates the truth so it returns UP when DOWN and vice versa, try this:

#!/bin/bash
r1="<UP>!"
r2="<DOWN>!"

if ping -c 1 0.0.0.1 >&1 > /dev/null ; then
    echo $r1
else
    echo $r2
fi

Also i've modified the ping command to ignore the usual output. Now it just displays up or down

Related