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

After login into telnet I need to login into another node, after executing command prompt is getting changed and also before getting prompt able to see some messages also printed, Please help me to change the prompt. after telent prompt is "test@user>" After running telnet command prompt gets changed to "ABC35>". whenever trying to give name prompt while passing cmd, getting timeout error.

$telnet = new Net::Telnet ( Timeout=>5,Errmode=>'die', Prompt => '/\>/ +i', Input_log=>"input.log", Dump_log=>"dump.log", Output_log=>"output +.log"); $telnet->open('ip Address'); $telnet->login('user', 'password'); print $telnet->cmd(String => $cmd_3g_login_node, Prompt => '/\ABC35 +>/i'); output: command timed-out attest.pl at line 3

Replies are listed 'Best First'.
Re: Net::Telnet + command prompt gets changed after command execution
by kcott (Archbishop) on Sep 14, 2016 at 21:23 UTC

    G'day kiran13,

    Welcome to the Monastery.

    [Disclaimer: I'm not a user of Net::Telnet. Others may have better answers. The following is just based on available documentation.]

    The Prompt values you show do not appear to match those shown in the documentation. Throughout Net::Telnet, all prompt values I saw include any trailing whitespace, i.e. they look like /xxx $/, rather than your /xxx/.

    Take a look at the EXAMPLES section which has quite a lot of information and starts with:

    "Setting prompt() to match a user's shell prompt can be tricky. ..."

    Here's some additional information to improve your code:

    • Always use the strict pragma.
    • Always use the warnings pragma.
    • Prefer lexical variables (e.g. declared with my) rather than the globally-scoped, package variables you appear to be using.
    • Avoid the discouraged Indirect Object Syntax: see "perlobj: Invoking Class Methods" for more about this.

    — Ken

Re: Net::Telnet + command prompt gets changed after command execution
by NetWallah (Canon) on Sep 14, 2016 at 22:31 UTC
    If your script has the same line numbers as what you posted, line 3 corresponds to:
    $telnet->open('ip Address');
    You may be running into firewall issues, incorrect port, or other basic communication configuration problem.

    use strict;
    use warnings;
    Look at the contents of dump.log and output.log for diagnosis.

            ...it is unhealthy to remain near things that are in the process of blowing up.     man page for WARP, by Larry Wall