in reply to Re: how to connect to a remote server through telnet and fire couple of commands?
in thread how to connect to a remote server through telnet and fire couple of commands?

Hi,

Thanks for your reply. Through manually I can log on to a remote server through putty by using telnet. Then I executed some commands to get some work done. But I have executed following code, but getting the error as follows "timed-out waiting for command prompt at telnet.pl "line 10

use Net::Telnet (); $t = new Net::Telnet (Timeout => 10, Prompt => '/bash\$ $/'); $host="10.10.10.10"; $username="xyz"; $passwd="xyz1"; $t->open($host); $t->login($username, $passwd); @lines = $t->cmd("who"); print @lines;

The remote server in my case is only supported telnet, because if I select SSH option in putty, I can't log on into the server.

To perform those tasks automatically I need some Perl code, as I am working in a automation project.

Regards,

Sanjay

  • Comment on Re^2: how to connect to a remote server through telnet and fire couple of commands?
  • Download Code

Replies are listed 'Best First'.
Re^3: how to connect to a remote server through telnet and fire couple of commands?
by poj (Abbot) on Jun 17, 2016 at 10:11 UTC

    What is the command prompt when you logon manually ?

    poj
Re^3: how to connect to a remote server through telnet and fire couple of commands?
by GotToBTru (Prior) on Jun 17, 2016 at 14:30 UTC

    As the documentation notes:

    The typical usage bug causes a time-out error because you've made incorrect assumptions about what the remote side actually sends. The easiest way to reconcile what the remote side sends with your expectations is to use "input_log()" or "dump_log()".

    Net::Telnet knows it has logged in when it sees the prompt you've told it to expect. The default *Prompt* is '/\$%#> $/'. That may work better than the bash$ in your example. Note that the value for prompt is treated as a regex, not a literal string.

    But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)