Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Net::telnet question for prompt only "$" and telnet session has menu

by spivey49 (Monk)
on Aug 28, 2008 at 13:39 UTC ( #707482=note: print w/replies, xml ) Need Help??


in reply to Net::telnet question for prompt only "$" and telnet session has menu

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

Replies are listed 'Best First'.
Re^2: Net::telnet question for prompt only "$" and telnet session has menu
by benlaw (Scribe) on Aug 29, 2008 at 09:44 UTC
    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;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://707482]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2019-12-15 15:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?