Checking host availability by using ping in bash scripts

前端 未结 8 2124
-上瘾入骨i
-上瘾入骨i 2020-11-29 20:07

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

8条回答
  •  情深已故
    2020-11-29 20:18

    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
    

提交回复
热议问题