Skip to content

if host pings execute command

#!/bin/sh
HOST="silveiraneto.net"
if ping -c 1 $HOST > /dev/null
then
   echo your command
fi
  • replace silveiraneto.net for your desired hostname or ip
  • ping sends only one package (-c 1) and ignores the text output
  • a ping is successful returns 0 and the if proceeds
  • replace the echo line with your command
Published inenglish

Be First to Comment

Leave a Reply

Your email address will not be published.