perl expect in Network automation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • perlandtcl
    New Member
    • Dec 2006
    • 1

    perl expect in Network automation

    Can any one suggest any link for perl expect....
    and few examples for automation of router and switch configurations .. apart from the tcl feature available in CISCO IOS
  • talexb
    New Member
    • Dec 2006
    • 1

    #2
    Originally posted by perlandtcl
    Can any one suggest any link for perl expect....
    and few examples for automation of router and switch configurations .. apart from the tcl feature available in CISCO IOS
    You've looked at IPC::Run on CPAN already?

    Comment

    • docsnyder
      New Member
      • Dec 2006
      • 88

      #3
      @perlandtcl

      Here is a simple script to create a ssh session to a remote host:

      Code:
      #!/bin/perl
      
      use Expect;
      
      #--- ENSURE TO HAVE SUFFICIENT COMMAND LINE ARGUMENTS ! ----------------------#
      if ( $#ARGV != 2 ) {
        printf("USAGE: $0 <host> <user> <pw>\n");
        exit(-1);
      }
      
      $host = shift;
      $user = shift;
      $pw   = shift;
      
      #--- CONFIGURATION -----------------------------------------------------------#
      $cmd    = "ssh -l $user $host";
      $prompt = "[Pp]assword";
      
      #--- START SSH LOGIN SEQUENCE ! ----------------------------------------------#
      $exp = new Expect();
      $exp->raw_pty(1);  
      $exp->spawn($cmd);
      
      #--- LOGIN AND INTERACT ! ----------------------------------------------------#
      $exp->expect(10000, [ $prompt => sub { $_[0]->send("$pw\n"); } ]);
      $exp->interact();
      
      __EOF__
      Feel free to substitute ssh by whatever (e.g. telnet, etc.).

      Greetz, Doc

      Comment

      Working...