K_M_McMahon has asked for the wisdom of the Perl Monks concerning the following question:

I am using Net::Telnet to access from one machine to another where I work. I am using it to monitor some processes so it can send me a message if there is a problem. Today, the script exited without warning me because it timed out waiting for a response from the remote machine. How can I trap that exit so that it sends me a message as it kills the script?

$t=new Net::Telnet (Timeout->10,prompt=>'/hello.*/'); $t->open($machine); $t->login($user,$pass); $t->cmd("some command");


It normally works, I have had it run for 12 hours at a time without having a timeout problem in the past, I have only seen it timeout on "some command" once, but I want it to notify if it does. I already have the process in place notify if only I knew how to call it on a timout.

Thanx,
-Kevin

Replies are listed 'Best First'.
Re: Catching a timeout
by mpeppler (Vicar) on Dec 05, 2003 at 23:23 UTC
    According to the Net::Telnet docs you need to use the errmode() method to set it to "return", and then check the error cause there.

    Alternatively, you could wrap the whole thing in an eval block, and then test $@.

    Michael

      Thanx, That's exactly what I wanted!

      -Kevin