Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Net::Telnet problem

by daemonchild (Acolyte)
on Aug 24, 2000 at 05:17 UTC ( [id://29363]=perlquestion: print w/replies, xml ) Need Help??

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

Hello all

I'm working on a script for work that telnets to a switch, grabs data from a couple of commands, prints to a file, and then gracefully exits. I have hit something of a roadblock however, and would really appreciate the help.

The offending code snippet looks like this:

@output = $t->cmd("show conduit"); $t->waitfor('/<--- More --->/'); @temp = $t->print(' '); push(@temp,@output);
I can log in fine, run commands fine, etc. The problem lies in the fact that the command "show conduit" prints data a page at a time, prompting you to hit the space bar for more data. I timeout every time after the first page, regardless of what i do, it seems.

Problem number two, is how to get the data after the first page into the array (once i get it to work)? Would my snippet work to that effect?

I don't have a whole lot of experience with this module, so any help is appreciated.

-- steve

Replies are listed 'Best First'.
RE: Net::Telnet problem
by BlueLines (Hermit) on Aug 24, 2000 at 05:55 UTC
    From the Net::Telnet manual:

    Debugging

    The typical bug causes a timeout error because you've made incorrect assumptions about what the remote side actually sends. The easiest way to reconcile what the remote side sends with your expectations is to use input_log() or dump_log(). dump_log() allows you to see the data being sent from the remote side before any translation is done, while input_log() shows you the results after translation. The translation includes converting end of line characters and stripping and responding to TELNET protocol commands.


    Use this to see what the other side is really returning (chances are there's an escape character or a spacing issue that you're missing). dump_log produces a huge amount of output, but you can find exactly what you should be waiting for. I'd be willing to be that you really want to be waiting for something like this:
    $t->waitfor('/<--- More ---> /');
    I've used this several times when automatic switch/router scripts mysteriously seem to "not work".....

    BlueLines

    Disclaimer: This post may contain inaccurate information, be habit forming, cause atomic warfare between peaceful countries, speed up male pattern baldness, interfere with your cable reception, exile you from certain third world countries, ruin your marriage, and generally spoil your day. No batteries included, no strings attached, your mileage may vary.
      This may be a simple IO question, but I have to ask...

      Could you give me an example of how you would turn on debugging?
      $t->dump_log('temp.txt');

      just writes out a blank file for me.

      similarly,
      $t->dump_log(<STDOUT>);

      gives no debugging information.
        Your first sample works for me:
        use Net::Telnet; my $telnet = Net::Telnet->new(Timeout => 10); $telnet->dump_log("dump.log"); $telnet->open("machine"); $telnet->login("user", "oass"); $telnet->close;
        I get a bunch of stuff (the stuff that goes in and out over the telnet connection) in dump.log. Are you actually trying to open a connection? I doubt you'll get anything in your dump_log file if you don't *do anything*. :)

        Oh, and your second snippet is wrong. That's not a filehandle; that's a diamond-operator *read* from a filehandle. STDOUT is the filehandle, <STDOUT> is you reading from the filehandle. You want

        $telnet->dump_log(*STDOUT);
Re: Net::Telnet problem
by Maclir (Curate) on Aug 24, 2000 at 06:55 UTC
    Hmmm - is this a Cisco router? Is there not a command to set the console page length? (rummaging around in my Cisco documentation . . . .)
    pager 0
    That disables paging.
RE: Net::Telnet problem
by vladdrak (Monk) on Aug 24, 2000 at 12:58 UTC
    You might try Net::Telnet::Cisco (http://www.cpan.org) which can help out on some quirks. Alternatvely, you can do a 'terminal length 0' and the prompts should go away. --Vlad
RE: Net::Telnet problem
by gumpu (Friar) on Aug 24, 2000 at 12:28 UTC

    Would it not be handier to use rsh or ssh for this:

    rsh -l user yourhost some_command > filewithoutput.txt

    The command will be run remotely and the output will go into the local file.

    If your very lazy you can even use a .rhosts files, in which case you don't even have to type in the password. Though this is not very secure. However since you are using telnet I guess you are not that worried about security.

    Have Fun

RE: Net::Telnet problem (Expect, Expect.pm)
by ybiC (Prior) on Aug 24, 2000 at 16:01 UTC
    While not at all Perlish, I've used the Expect language for scripts to do this very thing.

    I've not used it myself, but Expect.pm might be One Way To Do part of what you want.

    vladdrak already mentioned Net::Telnet::Cisco so I won't go into that.
        cheers,
        ybiC

RE: Net::Telnet problem
by vladdrak (Monk) on Aug 24, 2000 at 13:00 UTC
    You might try Net::Telnet::Cisco (CPAN) which can help out on some quirks you might find with Net::Telnet & IOS.

    Alternatvely, you can do a 'terminal length 0' and the prompts should go away.

    --Vlad
Re: Net::Telnet problem
by daemonchild (Acolyte) on Aug 24, 2000 at 20:39 UTC
    Thanks to all who helped!

    problem solved ... the "pager 0" command fixed both problems in one fell swoop!

    you guys are great

    -- steve

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-19 23:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found