问题
I tried to build a little telnet script to gain contact with the Net::Telnet module in Perl and I struggle with a command timeout when I try to receive the output.
$telnet = new Net::Telnet ( Timeout=>10);
$telnet->errmode("return");
$telnet->open('192.168.0.187');
$telnet->waitfor('/Username: $/i');
$telnet->print('admin');
$telnet->waitfor('/Password: $/i');
$telnet->print('admin');
$telnet->waitfor('/admin >$/i');
@output = $telnet->cmd('show');
#$telnet->waitfor('/admin >$/i');
print @output;
But what I get is:
command timed-out at telnet.pl line 12
Tried to increase the Timeout, set the errmode to return - but still getting that timeout. Nevertheless the output of "show" on the server needs about 1 sec, so something else must be wrong I guess in my script ?
回答1:
Please tell us what line 12 in your script is. Your snippet above doesn't have a line 12.
This will help to identify whether it fails during the connect already or during a later command. Are you sure it's the "show" command which fails?
来源:https://stackoverflow.com/questions/12049655/nettelnet-output-of-cmd-timed-out