[SATLUG] program or cron job to ping internal devices & email

Jon Mark Allen jm at allensonthe.net
Wed Jan 16 13:34:56 CST 2008


On Wed, 2008-01-16 at 09:53 -0600, Channing wrote:
[trim]
> Keep in-mind that a device may respond to a ping, but the underlying 
> service is provides (web, file transfer, printing, other app on another 
> port) may not be working correctly, or the O/S, or network may not be 
> allowing that service.  The only way to know that is if you monitor 
> those services specifically, in addition to monitoring your ping results.
[trim]

If you're set on writing your own scripts to monitor the services (and
not use something like nagios), netcat is your friend.

For example, I can check to see if port 80 is open on a machine like
this:
nc -vnz 1.1.1.1 80

-v is verbose, -n disables reverse DNS lookup, and -z tells it not to
send any data -- just attempt a connection.

If the port is open you will get:
(UNKNOWN) [1.1.1.1] 80 (http) open

And if it's closed you will get:
(UNKNOWN) [1.1.1.1] 80 (http) : Connection Refused

(The UNKNOWN refers to a reverse DNS lookup, which was disabled)

This command will produce a nice, one-line output that is easily
grepable for scripting.

Alternately, you could omit the -v flag to netcat and then it will only
produce output if the port is closed.  I prefer the -v flag, but to each
his own.

-- 
JM

/* Always make stupid moves, it confuses your opponent. */



More information about the SATLUG mailing list