Kamis, 13 September 2012

Create a Script to test Network Connection

 Thanks for visiting my blog and I hope what you learn here, will be for doing good or Justice to the World!





Create a Script called netck.sh .  The purpose of the script is to check network connectivity but in the process to learn how testing works as well.  Remember, when you execute a script and it is successful you will get a return of “0″ and if it is unsuccessful you will get any other number.
1. Create the script
#!/bin/bash
SITE="google.com"
ping -c 2 $SITE > /dev/null
if [ $? != 0 ]
then
echo $(date +%F)
echo Problems with the network!
fi

SITE=”google.com”
This variable is used for the site to test against.  You could build in the gateway, another server, etc. if you wanted to.
ping -c 2 $SITE > /dev/null
You will use ping and only ping the site 2 times, with the output being sent to /dev/null so it is not on screen.
if [ $? != 0 ]
This is a test that states that the success must be “0″, in other words the site must be up or it will send a message to the screen.
To test this change google.com to cnn.com(which does not accept pings) and you should see the error message.
then
echo $(date +%F)
echo Problems with the network!
fi
This reports the error message and the date if the ping is unsuccessful.
2. Test the script and then use other domains



Tidak ada komentar:

Poskan Komentar