Posts

Showing posts with the label Exit

Bash Ping Script File For Checking Host Availability

Answer : I would use this, a simple one-liner: while ! ping -c1 HOSTNAME &>/dev/null; do echo "Ping Fail - `date`"; done ; echo "Host Found - `date`" ; /root/scripts/test1.sh Replace HOSTNAME with the host you are trying to ping. I missed the part about putting it in the background, put that line in a shellscript like so: #!/bin/sh while ! ping -c1 $1 &>/dev/null do echo "Ping Fail - `date`" done echo "Host Found - `date`" /root/scripts/test1.sh And to background it you would run it like so: nohup ./networktest.sh HOSTNAME > /tmp/networktest.out 2>&1 & Again replace HOSTNAME with the host you are trying to ping. In this approach you are passing the hostname as an argument to the shellscript. Just as a general warning, if your host stays down, you will have this script continuously pinging in the background until you either kill it or the host is found. So I would keep that in mind when y...