Home > OS >  Ping script witch up or down status
Ping script witch up or down status

Time:09-07

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

CodePudding user response:

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.0 ; then
    echo $r1
else
    echo $r2
fi

~

  • Related