nav-left cat-right
cat-right
Home > Blog > Linux > shell: does the server exist ?

shell: does the server exist ?

The following function allows to test for the existens of a server in the network via ping, but with a better interface
#!/bin/sh
 
# --------------------------------------------------------- #
function server_exists ()
{
	# ping Optionen:
	# -c : Anzahl von pings
	# -n : nur numerisch, keine DNS Abfragen
	TESTSERVER=$1
	if (ping -c 1 -n -w 2 $TESTSERVER > /dev/null 2>&1) ; then
		# echo "$TESTSEVER: ping ok" 		
		return 0   # Success.		
	else
		# echo "$TESTSEVER: ping nicht ok" 
		return 1   # Failed 
	fi
}
It can be used as
if (server_exists $SERVER); then
	echo "> Rechner '$SERVER' existiert"
fi

Einen Kommentar schreiben

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

*


*

Du kannst folgende HTML-Tags benutzen: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Spam Protection by WP-SpamFree