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

Hello all I am running Net::telnet sessions to a device via a modem bank but I am hitting an issue when sometimes the device is not returning data usually due to a glitch. I have a Timeout set but that has to be a long timeout because some of the commands I run take a long time to complete and return a prompt (using prompts to fire the next command). What I want to do is listen for incoming data, if I do not have incoming data for say 1 minute I then want to bail out my connection. Can anyone point me in the right direction to check for incoming traffic?

Replies are listed 'Best First'.
Re: Net::telnet check for incoming traffic
by jethro (Monsignor) on Sep 17, 2008 at 12:39 UTC

    I would say, make a wrapper script around the long running commands that gives a feedback while doing the long running jobs. Like printing a '@' (or something else that can't occur in the output of the command itself) every second.

    The wrapper script could fork a second process (or thread) which executes the long running command, while the main process in a loop sleeps one second, prints a '@' and then does a non-blocking check whether the child finished already.

    For non-blocking waits see 'perldoc -f waitpid', but there are also some excellent modules that take care of the forking/threading/signaling or the forked process could simply create a file as signal that it has finished.

Re: Net::telnet check for incoming traffic
by kubrat (Scribe) on Sep 17, 2008 at 16:57 UTC

    I think that the select system call is ideal for your problem

     select RBITS,WBITS,EBITS,TIMEOUT