in reply to Re: Re: Re: Re: Net::Telnet time outs
in thread Net::Telnet time outs

Hmm, not quite, the command "being returned" is simply the "echo" of the command coming back, this happens immediatly after you send it, it's like when you type in a telnet window, for every keystroke you send it sends one back to display in your console. This does NOT mean the command is finished, the command could very well be hanging. How long does the command take to run in a regular telnet window? The fact that the dump log ends there means that nothing is coming back through the telnet connection, not even a prompt, which tells me the command (for whatever reason) is not finished.

Example: I sent a sleep command to one of my machines this was the output of it and the chain of events:
#Command I sent my @lines = $th->cmd("sleep 10"); #dump_log output #Matched a prompt < 0x00000: 72 65 78 40 44 72 69 7a 7a 74 3e 20 rex@Dri +zzt> #command is sent > 0x00000: 73 6c 65 65 70 20 31 30 0d 0a sleep 1 +0.. #command is immediatly echoed back < 0x00000: 73 6c 65 65 70 20 31 30 0d 0a sleep 1 +0.. #10 second wait here and then prompt returns < 0x00000: 72 65 78 40 44 72 69 7a 7a 74 3e 20 rex@Dri +zzt>

Remember that dump_log is both input and output logs!

"Nothing is sure but death and taxes" I say combine the two and its death to all taxes!

Replies are listed 'Best First'.
Re: Re: (5) Net::Telnet time outs
by mnlight (Scribe) on Aug 14, 2002 at 14:58 UTC
    The command will take any where from 1 to 30 seconds to run. I am dumping a sybase database tran log. The command is never executed almost like the command is sent then it exits from the Telnet session it then stops the job. When the command is executed in another window nothing is returned until it completes and goes back to the prompt.
      Ok, now for the obvious, is backup.pl in your path? Try running a different (very simple "hello world" style) perl script that is in the exact same place as backup.pl with the same permissions. This is seeming to be very strange. Also remove the waitfors, the cmd method will wait for timeout or prompt match, whichever is first.

      Make sure you are running with use strict ; and -w for as much info as possible.

      Also is there anything in @lines? Does the command return anything? (Although that is not likely whit the info in the dump log.).

      There must be something we are missing, with the info we have given you this should work just fine.

      "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!
        if I add waitfor('/NULL/') it will timeout long enough to run the command. but it then fails because of a bad match. I found this info in the telnet doc. "In an array context, just the output generated by the command is returned, one line per element. In other words, all the characters in between the echoed back command string and the prompt are returned. If the command happens to return no output, an array containing one element, the null string is returned. This is so the array will indicate true in a boolean context" How do I match this null string?
        In the script I open up two Telnet sessions. The first one is to dump the database. The second one is to dump the tran log both commands use the same backup.pl script the only difference is that to dump the tran you pass it the "Backup.Type=tran" parameter. Dumping the database works fine but when you backup the database the script returns an information message "Dumping database $dbname". for this session I have a waitfor(Dumping database) that seems to make it wait long enough to finish the command. When you dump the tran it returns nothing so I am not able to find a match on that command that I can waitfor. here is the code
        This part works fine. my $th = new Net::Telnet (input_log => "$dir/$log", dump_log => (*STDOUT), Host => "$server", Prompt => '/sybase?/'); $th->login("user", "$unixpass"); my @lines = $th->cmd("backup_sybase.pl Server.Name=$dbsrvr Backup.Data +base=$cltdb"); $th->waitfor('/Dumping database/'); print @lines; $th->waitfor('/sybase?/'); print @lines; print "******DUMPING $cltdb TRANSACTION******\n"; This part does not work. my $th = new Net::Telnet (input_log => "$dir/$log", dump_log => (*STDOUT), Host => "$server", Prompt => '/sybase?/'); $th->login("user", "$unixpass"); my @lines = $th->cmd(String => ("backup.pl Server.Name=$dbsrvr Backup.Database=$cltdb Backup.Type=tran"), Timeout + => 600); $th->waitfor('/sybase?/'); print @lines;