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

Dear all monks,
I have 2 question on NET::Telnet,
1. there is a 'Prompt => "/benlaw \#/"' option within creat new part, however my session has only prompt '$ ' then nothing... i try to type 'Prompt => "/\$ /"' but nothing i can see. what happen ?
Last unsuccessful login: Fri Aug 1 07:43:27 TAIST 2008 on /dev/pts/2 +from ixavsd Last login: Thu Aug 28 09:00:26 TAIST 2008 on ftp from ::ffff:169.169. +67.24 $ $
2. some of user account has User menu which insert within .profile..... if I would like to use net::telnet to retrieve result from remote command, how can i do for this case ??
Thanks a lot
  • Comment on Net::telnet question for prompt only "$" and telnet session has menu
  • Download Code

Replies are listed 'Best First'.
Re: Net::telnet question for prompt only "$" and telnet session has menu
by spivey49 (Monk) on Aug 28, 2008 at 13:39 UTC

    Posting your code might prove useful in answering your question.

    1. i try to type 'Prompt => "/\$/"'

    White space behind the '$' perhaps? Try prompt => '/\$\s/'

    2. The cmd() method should return the result of commands sent to the host

      Thanks for reply , here is my code ~
      use Net::Telnet; my ($username, $password)=("benlaw", "usertesting"); my %serverid = qw{ testsvr1 10.159.32.21 }; $t = new Net::Telnet (Timeout => 10, Dump_Log=> "err_dump.log", Output +_log=> "err_out.log", Prompt => "/\$\s/" ); @date = $t->cmd("date"); print @date; $t->close;

        If that's your entire code you're missing a couple of things like the open() and login() methods.

        Not sure the purpose of the serverid hash with a single key\value, but here's what the code should be with a hash:

        use strict; use warnings; use Net::Telnet; my ($username, $password)=("benlaw", "usertesting"); my $serverid{'testsvr1'} = '10.159.32.21'; my $t = new Net::Telnet (Timeout => 10, Dump_Log=> "err_dump.log", Output_log=> "err_out.log", Prompt => "/\$\s/" ); my @date; while ( my ($key,$value) = each(%servid){ $t->open($key=>$value); $t->login($username,$password); @date = $t->cmd("date"); print @date; $t->close; }

        Here's the way I would write it if I had a single server to log into:

        use strict; use warnings; use Net::Telnet; my ($username, $password)=("benlaw", "usertesting"); my $serverid = "10.159.32.21"; my $t, @date; $t = new Net::Telnet (Timeout => 10, Dump_Log=> "err_dump.log", Output_log=> "err_out.log", Prompt => "/\$\s/" ); $t->open($serverid); $t->login($username, $password); @date = $t->cmd("date"); print @date; $t->close;

Re: Net::telnet question for prompt only "$" and telnet session has menu
by leonidlm (Pilgrim) on Aug 28, 2008 at 15:34 UTC
    Hi,
    I once had a similar problem, although my solution won't help in your case I remember that using the following options of the Net::Telnet module helped me a lot in debugging, Just create your object with the following options:
    [Output_log => $file,] [Input_log => $file,]
    This options define a log files that will show you that responses Net::Telnet is working on in the background.
    Tell us if it helped :)
    Regards,
    Leonid M.
      Yup , thx, I opened the err dump log already, but it has only name password then my command only , it has nothing i can obtain. ~~ ~