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: 
There is advanced version of ping - "fping", which gives possibility to define the timeout in milliseconds.

```
#!/bin/bash
IP='192.168.1.1'
fping -c1 -t300 $IP 2>/dev/null 1>/dev/null
if [ "$?" = 0 ]
then
  echo "Host found"
else
  echo "Host not found"
fi

```
I liked the idea of checking a list like:

```
for i in `cat Hostlist`
do  
  ping -c1 -w2 $i | grep "PING" | awk '{print $2,$3}'
done

```

but that snippet doesn't care if a host is unreachable, so is not a great answer IMHO.

I ran with it and wrote

```
for i in `cat Hostlist`
do
  ping -c1 -w2 $i >/dev/null 2>&1 ; echo $i $?
done

```

And I can then handle each accordingly.