Selective Joining of Two Array Elements

2001-09-25 Thread Kevin der Kinderen

I have this list I've read into an array line by line:
 tty 81   bcain  Async 01:18:35  00:02:55  
 tty 83   dnguyenAsync 00:20:27  00:01:13  
 tty 85   cmandeville \
 Async 03:26:22  00:00:58  
 tty 88   twootenAsync 02:00:36  00:00:30  
 tty 89   jwatersAsync 00:13:37  00:00:32  
 tty 95   epastoriza Async 00:45:29  00:00:00  


The line starting with tty 85 is continued on the line after it so I'd
like to join them and close up the array. Any suggestions?

Once I get that figured out I'll be creating a cgi script which will put
this into a table. If I can get that far.

There's not much to show what I've done so far. It's built around
Net::Telnet::Cisco and performs a 'show caller' on a Cisco NAS. The
code's below with the cgi stuff commented out till I can get this
figured out.

Thanks,
Kevin


#!/usr/bin/perl

use warnings;
use strict;
use CGI qw( :standard );
use Net::Telnet::Cisco;

my $session = login();

# Execute a command
my @cmd_output = $session-cmd( 'show caller' );
$session-close;

#print header(), start_html( 'Dial-in Users' );
#print h2( Current Users of VAURA008 );
foreach (@cmd_output) {
#next if /(Active)|(Line)/;
#next if /\\$/; # my attempt to see if I could identify the line
 print $_;
}
#print end_html();




sub login {
my $session = Net::Telnet::Cisco-new( Host = 'vaura008' );
$session-login( 'kderkinderen', '' );

# Turn off paging
my @cmd_output = $session-cmd( 'terminal length 0' );
return $session;
}



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Duplicate Modules

2001-09-22 Thread Kevin der Kinderen

I've been trying to keep relatively up to date with modules using CPAN. 
I think I'm running into a little problem though. When I look through 
the perl directories after installing a new module some seem to install 
in a different part of the tree leaving the old module laying around.

For instance, I just downloaded Digest::MD5 and installed it. Then did a 
'find / -name MD5.* 2/dev/null' and came up with the following results:

/usr/share/man/man3/MD5.3pm.gz
/usr/share/man/man3/MD5.3pm
/usr/lib/perl5/site_perl/5.6.1/i386-linux/Digest/MD5.pm
/usr/lib/perl5/site_perl/5.6.1/i386-linux/MD5.pm
/usr/lib/perl5/site_perl/5.6.1/i386-linux/auto/Digest/MD5/MD5.bs
/usr/lib/perl5/site_perl/5.6.1/i386-linux/auto/Digest/MD5/MD5.so
/usr/lib/perl5/site_perl/5.6.1/MD5.pm
/usr/man/man3/MD5.3

/usr/lib/perl5/site_perl/5.6.1/MD5.pm is $VERSION = '2.02';  # $Date: 
2001/03/14 04:44:31 $
/usr/lib/perl5/site_perl/5.6.1/i386-linux/Digest/MD5.pm is $VERSION = 
'2.16';  # $Date: 2001/09/07 05:45:14  $

Do I delete the 2.02 version? Do I have to do this for every module I 
install or do I have something configured incorrectly that I have to 
hunt down?

My method for downloading and installing might be a bit unconventional. 
I use 'perl -MCPAN -eshell' and the 'r' command to find updated modules. 
I then get the modules and install them manually. I've had problems in 
the past installing from the shell.

Pointers in the right direction are appreciated.

Thanks,
Kevin


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Multiple Versions of Perl on One System

2001-08-25 Thread Kevin der Kinderen

I hope my question is relevant to the list.

I run Redhat 7.1.

I'd like to download the latest source for Perl and install it without
interferring with the version that's installed with Redhat. The
installed version can't be uninstalled (by me) because there's so many
dependencies on it.

The reason I'd like to do this is to keep up to date with the latest
versions of Perl and various modules while learning the language (plus
I'm a bit neurotic about having the latest of everything).

So, can I create a separate install of Perl and it's modules - maybe
somewhere in my home directory and be sure that the scripts I'm working
on - or the modules I load - affect only that version?

I've been told that I can update the installed version by getting the
source RPM and replacing components of it with the latest Perl source -
but that seems to lack the flexibility to blow it away and start all
over (my typical method for learning something new).

This is a personal system so the only one affected by my mistakes is me.

Thanks,
Kevin



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Version question - Comment on ping script

2001-08-18 Thread Kevin der Kinderen

I'd appreciate any comments on the code below. I run it like this:

./live seed.dat

or

echo zaphod | ./live

To get a quick scan of the reachability of my routers.

Question: What is the proper way to include a version number in the
code? When I do a perl -MCPAN -eshell and type r for the reinstall
recommendations - many modules show the version. Looking at the code to
some of these modules it seems it uses the vars pragma. According to
perldoc - it's obsolete. What is the correct way to do this - or does it
even make a difference.

For those who might want to comment - here's the code... (be kind - I'm
new at this).

./live seed.dat

#!/usr/bin/perl -w

use strict;
use warnings;
use Net::Ping;

my $p;
my $host;

our $VERSION = 0.01;

$p = Net::Ping-new(icmp);
foreach ()
{
chomp;
if ($_ eq ) {
print STDERR \nDone\n;
exit(0);
}
print $_ is ;
print NOT  unless $p-ping($_, 2);
print reachable.\n;
}
$p-close();




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Version question - Comment on ping script

2001-08-18 Thread Kevin der Kinderen

Thanks for the comments Smoot.

I thought while () {...} was the same as foreach () {...}.  Is this
because foreach provides a list context to the file being read and while
provides scalar context? I read this in the camel book but didn't understand
the significance. It makes a difference when the list is large?

Without the if statement in the code, if the last line is blank then I get
something like this as a return...

vaugw001 is reachable.
vadgw001 is reachable.
oh3gw001 is reachable.
tx88gw001 is NOT reachable.#done on purpose
 is NOT reachable.

The input file for above is:
---cut here---
vaugw001
vadgw001
oh3gw001
tx88gw001

---cut here---

Could I be looking at the blank line differently or be more careful with the
input file format?

Finally, is this the only way to run this script for a single host?

echo vaugw001 | live

Thanks again,
K

[EMAIL PROTECTED] wrote:

  Kevin der Kinderen [EMAIL PROTECTED] said:

 
  Question: What is the proper way to include a version number in the
  code? When I do a perl -MCPAN -eshell and type r for the reinstall
  recommendations - many modules show the version. Looking at the code to
  some of these modules it seems it uses the vars pragma. According to
  perldoc - it's obsolete. What is the correct way to do this - or does it
  even make a difference.

 I usually add a -V or --version option to the code which displays the
 current version number.  Take a look at Getopt::Std or Getopt ::Long
 for option processing.

  For those who might want to comment - here's the code... (be kind - I'm
  new at this).
 
  ./live seed.dat
 
  #!/usr/bin/perl -w
 
  use strict;
  use warnings;
  use Net::Ping;
 
  my $p;
  my $host;
 
  our $VERSION = 0.01;
 
  $p = Net::Ping-new(icmp);
  foreach ()
  {
  chomp;
  if ($_ eq ) {
  print STDERR \nDone\n;
  exit(0);
  }
  print $_ is ;
  print NOT  unless $p-ping($_, 2);
  print reachable.\n;
  }
  $p-close();

 Not a bad first start.  I an curious about the if.  Are you tagging
 the end of the device list with an empty line?  The foreach loop you
 have will read in the entire file and then each line in processed from
 the resulting list. I usually do I/O with a while loop e.g.

 while () {

 }

 This reads the input a line at a time.

 With the magic  you can also call your script like this:

 ./live seed.dat

 or even

 ./live seed1.dat seed2.dat

 The  will take each argument and treat it as a filename, opening each in
 turn.

 --
 Smoot Carl-Mitchell
 Consultant


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: modules

2001-08-08 Thread Kevin der Kinderen

Cool script. Why does a bunch list with a version of -- ???

Perl -- 5.6.1
Pod -- ???
RAS::AS5200 -- 1.04
SHA -- 2.01
Term::ANSIColor -- 1.04

Pod for example above.

Tks, K

Scott wrote:

 Here is some code that will list all installed modules

 #!/usr/bin/perl -w
 use ExtUtils::Installed;
 my $instmod = ExtUtils::Installed-new();
 foreach my $module ($instmod-modules()) {
 my $version = $instmod-version($module) || ???;
print $module -- $version\n;
 }

 -Original Message-
 From: Joe Bellifont [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, August 08, 2001 10:18 AM
 To: [EMAIL PROTECTED]
 Subject: modules

 How do I know what modules are installed ?
 Does the CGI_Lite module come bundled by default?

 _
 Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp

 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]

 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Calling a Method...

2001-08-08 Thread Kevin der Kinderen

Doh!

Thanks Robin.

K


Robin Lavallee (LMC) wrote:


 You have a syntax error, since you have not added a '$' in front of
 x,
 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Parsing a File

2001-08-05 Thread Kevin der Kinderen

I'm looking for pointers on what to do next. I have a file (the output
from 'show cdp neighbors detailed' on a Cisco router. I created a short
program which captures the output to a file - looks something like
this...

CDP log for ca5gw001.winstar.com
Created: 22:00:29 - 2001/08/01
-
Device ID: ca5gw002.winstar.com
Entry address(es):
  IP address: 10.1.25.3
Platform: cisco 4700,  Capabilities: Router
Interface: Ethernet3/0,  Port ID (outgoing port): Ethernet0
Holdtime : 167 sec

Version :
Cisco Internetwork Operating System Software
IOS (tm) 4500 Software (C4500-JS-M), Version 11.3(7), RELEASE SOFTWARE
(fc1)
Copyright (c) 1986-1998 by cisco Systems, Inc.
Compiled Tue 01-Dec-98 17:26 by kpma

-
Device ID: ca24gw001.winstar.com
Entry address(es):
  IP address: 10.0.252.141
Platform: cisco 2610,  Capabilities: Router
Interface: Serial2/2,  Port ID (outgoing port): Serial0/0
Holdtime : 156 sec

...

The first two lines are created during the capture and I hope to use
them as some sort of an ID.

Now I'd like to pull some key information from this file and set up a
table. I figured out how to read the file as a single string, strip the
newlines and double spaces and then split on the '-' so I can
now address each record as part of an array.

Here is $B[1]:

Device ID: wa2gw001.winstar.com Entry address(es): IP address:
10.0.249.117 Platform: cisco 7206VXR, Capabilities: Router Interface:
Hssi11/1/0.174, Port ID (outgoing port): Serial2/2.105 Holdtime : 121
sec Version : Cisco Internetwork Operating System Software IOS (tm) 7200
Software (C7200-IS-M), Version 12.0(7)T, RELEASE SOFTWARE (fc2)
Copyright (c) 1986-1999 by cisco Systems, Inc. Compiled Tue 07-Dec-99
16:36 by phanguye advertisement version: 2

The next step would be to pull out the info without all the extraneous
information. The output should eventually look something like (separated
with tabs):

ca5gw001E3/0ca5gw002E010.1.25.34700router
11.3(7), fc1
ca5gw001S2/2ca24gw001S0/010.0.252.1412610
router12.0(4)T, fc1
...

I'm not coming close to a general way to pull this information out of
each array element. I figure I have to use regular expressions to match
the info I want - maybe use $1, $2, $3... if I can figure out what to
match.

This post is long enough. If anyone's interested, I could post the code
fragments I've come up with so far.

I've got the Perl CD Bookshelf - just can't put it into practice yet.

Thanks,
Kevin



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]