Sponsored Content
Full Discussion: Parsing Array - Newbie
Top Forums Shell Programming and Scripting Parsing Array - Newbie Post 302362271 by xmaverick on Thursday 15th of October 2009 12:28:20 PM
Old 10-15-2009
Parsing Array - Newbie

Hello,

I'm a newbie to the world of programming and so i decided to learn perl. I'm working on a project that telnets into a Cisco router and eliminates a specific line but i can't seem to get the thing to work. I dump the output into an array but i'm having a difficult time looking for the string in the array. Any suggestions? Here is the code:

Code:
#!/usr/bin/perl -w

use strict;
use warnings;
use Net::Telnet;

my $ip = $ARGV[0];
my $pass = "xxxx";
my $pass2 = "xxxxx";
my $t=new Net::Telnet(Errmode=>'return',Input_Log => "/tmp/input.log", Output_Log =>
"/tmp/output.log",Timeout=>30);
my $file = "/tmp/input.log";


$t->open($ip);
 if($t->errmsg) { my $err=$t->errmsg; return $err; }
 my ($prompt) = $t->waitfor('/Password: $/');
    if($t->errmsg) { my $err=$t->errmsg; return $err; }
    $t->print("$pass");
    $t->waitfor('/>$)/');
    $t->print('en');
    $t->waitfor('/Password: $/');
    $t->print("$pass2");
    $t->waitfor('/#$/');
    my @out=$t->cmd(String=>'sh run | inc connect',Prompt=>'/#$/');
    my $line = @out;
    t->print("config t");
    $t->waitfor('/#$/');
    $t->print(" no $line") if $line =~ '/^connect sgsn/';
    $t->waitfor('/#$/');
    $t->print("end");
    $t->waitfor('/#$/');
    $t->print("logout");
   
   


    
    
    ##### email results of cross connect bounce ####

    my $to = 'xxxx.xxx@xxx.com';
    chomp (my $date=`date '+%H:%M:%S %Z %a %b %e %Y'`);
    
    my $subj="\"Cross Connects Bounced\"";
                open(MAILX, "|/usr/bin/mailx -s $subj $to");
                print MAILX "The cross connects for $ip were bounced at $date, @out\n";
                close(MAILX);


Once the script logs into the router it executes a "sh run | inc connect " and dumps an output like so into an array.
Code:
connect sgsn Serial1/0:6 701 l2transport
xconnect 172.19.231.227 701 pw-class fr-xconnect

The next job is to search for the connect sgsn Serial1/0:6 701 l2transport to see if it has it in the array and if it does i want the script to type into the prompt "no connect sgsn Serial1/0:6 701 l2transport"

Last edited by pludi; 10-15-2009 at 02:51 PM.. Reason: code tags, please...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl parsing compared to Ksh parsing

#! /usr/local/bin/perl -w $ip = "$ARGV"; $rw = "$ARGV"; $snmpg = "/usr/local/bin/snmpbulkget -v2c -Cn1 -Cn2 -Os -c $rw"; $snmpw = "/usr/local/bin/snmpwalk -Os -c $rw"; $syst=`$snmpg $ip system sysName sysObjectID`; sysDescr.0 = STRING: Cisco Internetwork Operating System Software... (1 Reply)
Discussion started by: popeye
1 Replies

2. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

3. UNIX for Dummies Questions & Answers

UNIX newbie NEWBIE question!

Hello everyone, Just started UNIX today! In our school we use solaris. I just want to know how do I setup Solaris 10 not the GUI one, the one where you have to type the commands like ECHO, ls, pwd, etc... I have windows xp and I also have vmware. I hope I am not missing anything! :p (4 Replies)
Discussion started by: Hanamachi
4 Replies

4. Shell Programming and Scripting

perl newbie . &&..programming newbie (question 2)

Hello everyone, I am having to do a lot of perl scripting these days and I am learning a lot. I have this problem I want to move files from a folder and all its sub folders to one parent folder, they are all .gz files.. there is folder1\folder2\*.gz and there are about 50 folders... (1 Reply)
Discussion started by: xytiz
1 Replies

5. Shell Programming and Scripting

perl newbie . &&..programming newbie

Hi, I am new to programming and also to perl..But i know 'perl' can come to my rescue, But I am stuck at many places and need help..any small help is much appreciated... below is the description of what i intend to acheive with my script. I have a files named in this format... (13 Replies)
Discussion started by: xytiz
13 Replies

6. Shell Programming and Scripting

Parsing XML elements and store them in array

Hi Friends Im so confused with using 'for' loop in ksh. I have a xml like the following: <serviceProvider> <serviceProviderID>1</serviceProviderID> <serviceProviderName>Balesh</serviceProviderName> <serviceFeeAmount>30.00</serviceFeeAmount> </serviceProvider>... (2 Replies)
Discussion started by: balesh
2 Replies

7. Shell Programming and Scripting

PERL : Read an array and write to another array with intial string pattern checks

I have an array and two variables as below, I need to check if $datevar is present in $filename. If so, i need to replace $filename with the values in the array. I need the output inside an ARRAY How can this be done. Any help will be appreciated. Thanks in advance. (2 Replies)
Discussion started by: irudayaraj
2 Replies

8. Shell Programming and Scripting

Looking for help with parsing file contents in bash [newbie]

Hi I'm just messing around with bash and trying to learn it because I have a course next semester dealing with OS design where we need to know how to use SSH client and either bash or ksh. I've never done shell scripting before. I just started today and I was wondering how parsing files... (1 Reply)
Discussion started by: mehungry
1 Replies

9. Shell Programming and Scripting

Bash 3.2 - Array / Regex - IF 3rd member in array ends in 5 digits then do somthing...

Trying to do some control flow parsing based on the index postion of an array member. Here is the pseudo code I am trying to write in (preferably in pure bash) where possible. I am thinking regex with do the trick, but need a little help. pesudo code if == ENDSINFIVEINTS ]]; then do... (4 Replies)
Discussion started by: briandanielz
4 Replies

10. Shell Programming and Scripting

Newbie help - parsing through a file

Hello guys, I am a newbie to all of this - I'd like some help with a file I have. It's a ~100mb CSV file with approximately 30 columns. What I'd like to do is to search through the file and REMOVE any lines with a certain case insensitive string in any of the columns: So my file looks... (4 Replies)
Discussion started by: Lokhtar
4 Replies
rancid(1)						      General Commands Manual							 rancid(1)

NAME
rancid - Cisco configuration filter SYNOPSIS
rancid [-dlV] (-f filename | hostname) DESCRIPTION
rancid is a perl(1) script which uses the login scripts (see clogin(1)) to login to a device, execute commands to display the configuration, etc, then filters the output for formatting, security, and so on. rancid's product is a file with the name of it's last argument plus the suffix .new. For example, hostname.new. There are complementary scripts for other platforms and/or manufacturers that are supported by rancid(1). Briefly, these are: agmrancid Cisco Anomaly Guard Module (AGM) arancid Alteon WebOS switches arrancid Arista Networks devices brancid Bay Networks (nortel) cat5rancid Cisco catalyst switches cssrancid Cisco content services switches erancid ADC-kentrox EZ-T3 mux f10rancid Force10 f5rancid F5 BigIPs fnrancid Fortinet Firewalls francid Foundry and HP procurve OEMs of Foundry hrancid HP Procurve Switches htranicd Hitachi Routers jerancid Juniper Networks E-series jrancid Juniper Networks mrancid MRTd mrvrancid MRV optical switches mtrancid Mikrotik routesrs nrancid Netscreen firewalls nsrancid Netscaler nxrancid Cisco Nexus boxes prancid Procket Networks rivrancid Riverstone rrancid Redback srancid SMC switch (some Dell OEMs) trancid Netopia sDSL/T1 routers tntrancid Lucent TNT xrancid Extreme switches xrrancid Cisco IOS-XR boxes zrancid Zebra routing software The command-line options are as follows: -V Prints package name and version strings. -d Display debugging information. -l Display somewhat less debugging information. -f rancid should interpret the next argument as a filename which contains the output it would normally collect from the device ( hostname) with clogin(1). SEE ALSO
control_rancid(1), clogin(1), rancid.conf(5) CAVEATS
Cisco IOS offers a DHCP server that maintains a text database which can be stored remotely or on local storage. If stored locally, the file changes constantly and causes constant diffs from rancid. If this file's name ('ip dhcp database') matches the regex dhcp_[^[:space:].].txt, it will be filtered. For Catalyst switches running CatOS, type cat5, the prompt must end with '>'. clogin(1) looks for '>' to determine when a login is successful. For example: cat5k> cat5k> enable Password: cat5k> (enable) rancid works on Cisco Catalyst 1900 series switches that are running Enterprise Edition software. This software provides a menu at connection time that allows a command line interface to be used by entering 'K' at the prompt. 26 April 2011 rancid(1)
All times are GMT -4. The time now is 08:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy