Amit Saxena wrote:
> I want a perl ping script (console based) to monitor server up/down
state.

Here's something I wrote ~2000 FWIW.  It looks like I was still on
dial-up, and wanted to ping an Internet host every ~10 seconds or so to
prevent my connection from being dropped due to inactivity.  Briefly
testing just now, it seems to work okay on Cygwin.  YMMV.


HTH,

David



#! perl -w
use strict;

use Term::ReadKey;

ReadMode('cbreak');

my $char;
my $i = 0;
my $address = shift @ARGV;

while(1)
{
        if (defined ($char = ReadKey(-1)) )
        {
                # input was waiting and it was $char
                goto BYE;
        }
        else
        {
                # no input was waiting
                sleep(1);
        }

        if ($i % 10 == 0)
        {
                my $answer = `ping $address`;
                print $answer;
        }

        $i++;
}
BYE:

ReadMode('normal');                  

__END__

usage: perl tickle [IPADDRESS]
A Win9x Perl script that pings chosen address every ten seconds.
Requires ActiveState Perl v5.005 and TermReadKey module.

Suggested use:

1. Right-click on the desktop and select New | Shortcut.

2. "Create Shortcut" dialog -- Set "Command Line" to
   "PERLPATH TICKLEPATH IPADDRESS", where PERLPATH is the full path to
   your Perl executable ("C:\Perl\bin\perl.exe", etc.), TICKLEPATH is
   the full path to the script ("d:\david\code\perl\tickle\tickle",
   etc.), and IPADDRESS is an IP address on the internet, such as your
   ISP's primary DNS server (127.0.0.1, etc.).  Click "Next >".

3. "Select a Title for the Program" dialog --  Set "Select a name for
   the shortcut to "tickle".  Press "Finish".

4. Connect to your ISP.

5. Double-click on the "tickle" shortcut.  Watch as it pings your ISP.
   Minimize the window and begin on your internet work.

6. When you are ready to disconnect from the internet, restore the
  "tickle" window.  Press any key.  Script will terminate and window
   will close.


Copyright 2000 by David Christensen
This script is granted into the public domain, without warrantee.


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to