Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

problems with Net::Telnet (i think)

by krujos (Curate)
on May 04, 2002 at 20:12 UTC ( [id://164053]=perlquestion: print w/replies, xml ) Need Help??

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

I am trying to access multiple clients with my script using Net::Telent. I want to search a bunch of files and look for a specific string. My problem is Net::Telent is returning the error  timed-out waiting for command prompt at findHost.pl line 25 That is the line where I try to login. When I use telnet manually I can get into the machines, I also am pretty sure I have the regexp for the Prompt variable correct. If anyone can provide a little wisdom into my problem I would be grateful. here is the code in question...
#!/usr/local/bin/perl -w use strict; use Net::Telnet (); #get the contents of the array from mike. my (@files, $t, @hosts, $result,$cpu); $hosts[0]="aster"; $hosts[1]="candytuft"; my $username="user"; my $password="pass"; foreach $cpu (@hosts) { #use the net telnet module here. $t = new Net::Telnet (Timeout => '30', Prompt => '/[%#>] $/', host=>$cpu); print " $cpu \n"; $t->login($username, $password); $t->cmd("cd /usr/openv"); print $t->cmd("usr/bin/ls"); @files = $t->cmd("find . -type f -print | xargs grep \"domain. +com\" /dev/null"); print "-------------\n"; print "Results for $cpu\n"; print "-------------\n"; my $loc; foreach $loc (@files) { print "-- $loc\n"; } my $tmp = $t->dump_log(); print "This is the dump_log \n$tmp \n"; print "\n\n"; }
Thanks agian Josh

Replies are listed 'Best First'.
Re: problems with Net::Telnet (i think)
by krujos (Curate) on May 04, 2002 at 21:11 UTC
    problem B:
    and this will probably fall under the ranting and raving category. Why when it times out does it kill the whole script? I didn’t tell it to do that. Does anyone know of a way to fix that?
    thanks
      Per the Net::Telnet documentation, the default Errmode is "die". You can set it to be "warn" or "print" if you'd like in the contructor:
      my $obj = Net::Telnet->new(Errmode => 'return');


          --jb
Re: problems with Net::Telnet (i think)
by krujos (Curate) on May 06, 2002 at 15:45 UTC
    doh! Problem Solved. if you change the line
    host=>$cpu
    to
    Host=>$cpu
    things work much better.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://164053]
Approved by sm3g
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-25 05:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found