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

Hi all, I am getting errors, even though successful telnet on machine (observed in Telnet log file also I have put below code and telnet log content ) Telnet log code section:

my $comdb_copy_obj= new Net::Telnet (Timeout => 20, Input_log=>($Prepa +reENB_Telnet_copycomdb_log)); if ($comdb_copy_obj->open(Host => $tftp_ServerIP, Port =>'23') != +1) { print ("connection success"); return "ERROR_CONNECTION" ; }

"Below are the telnet log file PrepareENB_Telnet_copycomdb_log.txt content

Ubuntu 12.04.3 LTS tdd login: tdd Password: Last login: Fri Dec 19 12:08:10 IST 2014 from ThinkCentre-E73.local on pts/9 Welcome to Ubuntu 12.04.3 LTS (GNU/Linux 3.8.0-29-generic i686) * Documentation: https://help.ubuntu.com/ 365 packages can be updated. 179 updates are security updates. New release '14.04.1 LTS' available. Run 'do-release-upgrade' to upgrade to it. tdd:~$"

But even for successful telnet on machine (which we can confirm from above output and prompt ) I found below errors for Wait function.

Uncaught exception from user code: pattern match timed-out at /media/TDD_ATF/PrepareENB.pm line 55 at /usr/share/perl5/Net/Telnet.pm line 2036

Net::Telnet::_croak('Net::Telnet=GLOB(0x1de46c8)', 'pattern match timed-out') called at /usr/share/perl5/Net/Telnet.pm line 539 Net::Telnet::error('Net::Telnet=GLOB(0x1de46c8)', 'pattern match timed-out') called at /usr/share/perl5/Net/Telnet.pm line 1995 Net::Telnet::waitfor('Net::Telnet=GLOB(0x1de46c8)', 'Match', '/tdd:~$/i', 'Timeout', 200) called at /media/TDD_ATF/PrepareENB.pm line 55

And below are my code section where I am getting error

sub Copy_config { my $comdb_copy_obj= new Net::Telnet (Timeout => 20, Input_log=>($Prepa +reENB_Telnet_copycomdb_log)); if ($comdb_copy_obj->open(Host => $tftp_ServerIP, Port =>'23') != +1) { print ("connection success"); return "ERROR_CONNECTION" ; } my $user = "tdd"; my $password = "tdd123"; my $comdbcopy_cmd = "cp -rf /home/tdd/LTE/ATF/TDD_ATF/$BW/$TM/$UD/ +eNBcfg10.102.81.60.bin /tftpboot/" ; my $prompt = '/tdd:~$/i'; $comdb_copy_obj->open($tftp_ServerIP); $comdb_copy_obj->waitfor('/tdd login:/i'); $comdb_copy_obj->print($user); $comdb_copy_obj->waitfor('/Password:/i'); $comdb_copy_obj->print($password); 1. $comdb_copy_obj->waitfor('/tdd:~$/i'); 2. $comdb_copy_obj->waitfor(Match => $prompt, Timeout => $comdb_co +py_obj->timeout * 10 ); 3. $comdb_copy_obj->waitfor($comdb_copy_obj->prompt); $comdb_copy_obj->print($comdbcopy_cmd); $comdb_copy_obj->waitfor(Match => $prompt, Timeout => $comdb_copy_ +obj->timeout * 10 ); #$comdb_copy_obj->waitfor('/tdd:~$/i'); #$comdb_copy_obj->waitfor($comdb_copy_obj->prompt); $comdb_copy_obj->print('exit'); $comdb_copy_obj->close; }

In above code I have tried all three options 1,2,3 for wait function but none of them worked and got same error mentioned above. Can anyone please help me . Thanks a bunch in advance.

Replies are listed 'Best First'.
Re: Error in Telnet wait function even though succesful telnet on machine
by RichardK (Parson) on Dec 29, 2014 at 13:34 UTC

    $ is a meta character meaning end of line, so if you want to match it in 'tdd:~$' you'll have to escape it. See the docs Net::Telnet for more details and advice on debugging.

    so :-

    obj->waitfor('/tdd:~\$$'); # search for tdd:~$ at the end of a line
      Thanks a lot Richard, I missed that \$ eliminator earlier and now it worked .