Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6653299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:15:06+00:00 2026-05-26T01:15:06+00:00

I currently have an implementation using the pexpect python module, which interacts with Juniper,

  • 0

I currently have an implementation using the pexpect python module, which interacts with Juniper, Cisco routers. It spawns a child application and runs command like ‘show version’ and logs the output.

I am looking for a better way to carry out this process, since if something changes on the switch end (a space or a colon in the prompt after an OS upgrade), then the program will not work. I think Juniper has an API to carry out such operations, but I don’t think Cisco has one. I also need to extend this to other switches like HP etc.

Is there a generalized way I can approach this?

I also don’t mind writing different code for different devices if required, if a more standard approach than pexpect exists.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:15:08+00:00Added an answer on May 26, 2026 at 1:15 am

    Using some version of expect is the accepted way of doing this. There’s already a mature piece of OSS scripts for doing terminal interaction with most networking devices form most vendors. The same problem exists, but a lot more eyeballs are looking at it and updating things when vendors change prompts.

    Check out RANCID.

    Here’s a quick example of a script I wrote based on RANCID to harvest ACL hit counts on ASAs:

    #!/usr/bin/perl
    
    use strict;
    use Getopt::Std;
    
    my $usage = "Usage: gethitcnt.pl -c configfile -o outputdir\n\n";
    my %opts;
    
    getopts('hc:o:', \%opts);
    
    my $login = sprintf "~%s\/bin\/clogin.in", $ENV{'HOME'};
    my $loginrc = sprintf "~%s\/.cloginrc", $ENV{'HOME'};
    my $cmdfile = sprintf "~%s\/cmd", $ENV('HOME');
    my $date = getdate;
    my ($config,$outdir);
    
    unless (-e $login) {
     die "Cannot find $login\n\n";
    }
    
    unless (-e $loginrc) {
     die "Cannot find $loginrc\n\n";
    }
    
    if ($opts{h} or !$opts{c}) {
     die $usage;
    }
    
    if ($opts{o}) {
     $outdir = $opts{o};
    } else {
     $outdir = $ENV{'PWD'};
    }
    
    if (-e $opts{c}) {
     $config = getconfig($opts{c});
    } else {
     die "Cannot open config file $opts{c}\n\n";
    }
    
    foreach my $firewall (keys %$config) {
     foreach my $acl (@{$config->{$firewall}}) {
      open (CMD,>$cmdfile);
      print CMD "show access-list $acl\n";
      print CMD "clear access-list $acl counters\n";
      close (CMD);
      my $command = ($login,"-x",$cmdfile,$firewall)
      open (TMP,"$command |");
      my $outfile = sprintf "%s\/%s-%s-%s.txt", $outdir, $firewall, $acl, $date;
      open (OUTFILE,>$outfile);
      foreach my $line (<TMP>) {
       if ($line =~ /\s*(access-list.*\(hitcnt=\d+\))/) {
        print OUTFILE "$1\n";
       }
      }
      system ("rm",$cmdfile);
     }
    }
    
    sub getconfig {
     my $configfile = shift;
     open(CONFIG,$configfile);
     my $out;
     foreach (<CONFIG>) {
      chomp;
      my @$elements = split(/,/);
      my $host = shift(@$elements);
      $out->{$host} = $elements;
     }
     close(CONFIG);
     return($out);
    }
    
    sub getdate {
     my @time = localtime;
     my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
     my $month = $abbr[$time[4]];
     my $out = sprintf "%s-%d", $month, $time[3];
     return($out);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a functioning in-house Windows Forms application which extensively uses the DataGridView
I currently have made a UnitOfWork implementation which wraps both the database connection and
I currently have a application which will display the time allocated to a user
I have some forms, and am currently using an implementation as described below: <form
I currently have an issue in my DLR language implementation where subsequent calls to
I currently have an MS Access application that connects to a PostgreSQL database via
I currently have an existing database and I am using the LINQtoSQL generator tool
I currently have heavily multi-threaded server application, and I'm shopping around for a good
I currently have a working, simple language implemented in Java using ANTLR. What I
I am currently replacing some home baked task functionality with a new implementation using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.