Shell Scripts February 24, 2008 0

Validate connection to remote host – Sprawdzanie łączności z hostem

A simple script to test connection to a remote host


#ping waits n of seconds 

ping -c $n_sec $REMOTE_HOST_IP >/dev/null   

if [ $? -eq 0 ]; 
  then echo "Ping OK" 
  else "Host is not available" 


Below script will check the connection, if connection cannot be established for 30 seconds it will write results to root session screen. Very nice and small network monitor tool, which can be executed by e.g. a crontab.

/bin/ping -c1 -W30 > /dev/null 2>&1   
if [ $? != 0 ]; 
  then write root < /root/noconnect #this file stores the message 

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.