|
|
To print: Select File and then Print from your browser's menu
-------------------------------------------------------------- This story was printed from ZDNet Australia. --------------------------------------------------------------
|
Free network uptime alarms with Linux By Jack Wallen, Jr., TechRepublic June 14, 2002 URL: http://www.zdnet.com.au/news/business/soa/Free-network-uptime-alarms-with-Linux/0,139023166,120265970,00.htm
If your management duties are keeping you so busy that you don't have time to check your network for uptime, don't panic and hire another employee. Check out this simple Linux bash script that will handle the monitoring for you.
Let's face it; a critical IT job is keeping your network up. Although operating systems and hardware are making this a much easier task, nothing is infallible. No matter how well your network was designed, no matter how many 9s are in your OS's uptime promise, your network is going to come crashing down. When that happens, you must react and react immediately. Of course, without the knowledge of a downed network, you cannot possibly react.
I'm going to show you a simple way to set up a free and reliable network alarm system that will sound off if your network connection fails. We are going to try to make this system as flexible and simple as possible. Using Linux, bash, and cron Seeing as how my favourite OS is Linux, I thought I'd start there. It only took me about 10 minutes to come up with this simple alarm system using crontab and a simple bash script. My idea was basically to write a script that would ping an IP address (or URL) and react accordingly. The primary goal here is to loop a sound if the ping fails. For this to work, you will have to have a working Linux installation, complete with network connection and sound. The first step is to create the bash script that will serve as our watch guard. The script (called netwatch) looks like this: While
And that's it! URLs and sounds Note that both the URLs and the sounds in the above file are user-configurable.
Basically, this file runs a single ping on a URL; if the ping is successful, the script ends. If the ping is unsuccessful, the script runs the command (we'll substitute an actual .wav file found in RedHat 7.1):
until the script is killed with
After you create the file, there are two more steps to take before it will actually work. The first step is to change the permissions of the file so that it is executable with the command
or
The next step is to create a crontab entry that will run the netwatch at certain intervals. We create our crontab file like so:
which will open the crontab editor. (It's actually the vi editor focused on editing a special file.) Within the crontab editor, you will hit the I key and then enter the following (using my home directory as an example):
which will run the netwatch script every 10 minutes. Once you've entered the above line, hit the [Esc] key and then [Shift]colon (:). Then, type wq and press [Enter]. As soon as you've exited the crontab application, the crontab will go into effect and the netwatch script will begin monitoring the status of your network. Should the ping command not work, you will be greeted with a continual sound until the killall command is run. One issue with this monitor is that it depends on the uptime of the Linux box's connection to the network it is testing. It also does not take into account all routes on your network. Of course, you could make this much more complex by setting up your routing table so that the script actually tests all possible routes. Say, for instance, you want to have the monitor test both an external and an internal network. For this, you can add two ping lines to the script: the first to an external URL (or IP address) and the second to an internal address. Let's say you want to monitor your internetwork as well as your external connection. You could alter your netwatch script to look like:
While
Now the alarm will sound anytime either the internal or external connection fails. Conclusion The best thing about this system (and Linux in general) is that it allows you a world of creativity to make the system fit your needs. Use your imagination with this type of scripting, and you'll see that Linux can do things most OSs can't.
TechRepublic is the online community and information resource for all IT professionals, from support staff to executives. We offer in-depth technical articles written for IT professionals by IT professionals. In addition to articles on everything from Windows to e-mail to fire walls, we offer IT industry analysis, downloads, management tips, discussion forums, and e-newsletters.
Copyright © 2009 CBS Interactive, a CBS Company. All Rights Reserved. |