Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Seeking Help w/ Expect.pm...

by kendroid (Beadle)
on Apr 20, 2001 at 01:37 UTC ( [id://74006]=perlquestion: print w/replies, xml ) Need Help??

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

Hi All,

I'm trying to write a script that backs up router configs. I'm able to use Net::Telnet::Cisco to log into and enable the routers. My problem is, whenever I try to remotely copy the config files (copy startup-config tftp), it waits for more input (remote host & destination filename) and doesn't give a prompt back to me.

My inclination is to use Expect.pm. In fact, if I weren't inclined to use Perl for this -- it needs to be scalabe -- I'd just use plain vanilla expect. Unfortunately, the Expect.pm documentation is *very* crummy.

Any suggestions?

Thanks muchly,
Kendrick.

Replies are listed 'Best First'.
Re: Seeking Help w/ Expect.pm...
by nardo (Friar) on Apr 20, 2001 at 10:25 UTC
    I've never used Expect.pm, but I have used expect. I've taken a brief perusal of the Expect.pm documentation, but keep in mind this is the first time I've actually written code for it. I notice that the documentation does not have a send() function, only a send_slow(), which seems a bit odd, so there may be another preferred way of sending data with Expect.pm without a pause between characters, but I'm going to use send_slow().

    $expectobj = Expect->spawn('telnet', $cisco_hostname) $expectobj->expect($timeout, 'ogin:'); #the above line assumes the router will give you a login #prompt which ends in 'ogin:', you may need to modify it #to fit your needs $expectobj->send_slow(0, $login_name, "\r\n"); $expectobj->expect($timeout, 'ord:'); $expectobj->send_slow(0, $password, "\r\n"); $expectobj->expect($timeout, $shell_prompt); #$shell_prompt should be something like '$' or '#' or whatever #let's you know that you can start typing commands $expectobj->send_slow(0, "copy startup-config tftp\r\n"); sleep(1); #just to make sure the previous command has been processed $expectobj->send_slow(0, $remainder_of_data_to_send);
    That's it, you should get the idea from there. The documentation for expect should help you understand the Expect.pm documentation as most Expect.pm functions have an expect function of the same name.
      Thanks nardo -- I was anxious to use the Net::Telnet::Cisco module (I'm relatively new to Perl, so I'm always anxious to learn new modules), but anything that gets the task done is a Good Thing. :)

      Kendrick.

Re: Seeking Help w/ Expect.pm...
by kendroid (Beadle) on Apr 20, 2001 at 01:38 UTC
    Oops -- s/scalabe/scalable :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-24 23:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found