Question: I want to write a script, that would keep checking if any of the devices in network, that should be online all day long, are really online. I tried to use ping, but

```
if [ "`ping -c 1 some_ip_here`" ]
then
  echo 1
else
  echo 0
fi

```

gives `1` no matter if I enter valid or invalid ip address. How can I check if a specific address (or better any of devices from list of ip addresses) went offline?

Answer: 
I can think of a one liner like this to run

```
ping -c 1 127.0.0.1 &> /dev/null && echo success || echo fail

```

Replace 127.0.0.1 with IP or hostname, replace echo commands with what needs to be done in either case.

Code above will succeed, maybe try with an IP or hostname you know that is not accessible.

Like this:

```
ping -c 1 google.com &> /dev/null && echo success || echo fail

```

and this

```
ping -c 1 lolcatz.ninja &> /dev/null && echo success || echo fail

```
```
up=`fping -r 1 $1 `
if [ -z "${up}" ]; then
    printf "Host $1 not responding to ping   \n"
    else
    printf "Host $1 responding to ping  \n"
fi

```