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

Also note that if by "putty" you actually mean an ssh connection, I recommend Net::SSH2 or Net::SSH::Any for use on Windows.

Net::Telnet has been mentioned already, but for automation, you can also use the included plink.exe for connections to other hosts.

Really do talk to your network administrators about the availability of ssh access. Using preshared keys is much better than storing passwords and sending plaintext.

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

Replies are listed 'Best First'.
Re^2: how to connect to a remote server through telnet and fire couple of commands?
by nayaksan76 (Initiate) on Jun 17, 2016 at 07:57 UTC

    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

      What is the command prompt when you logon manually ?

      poj

      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)