[ale] Bash Prompt Programming Question

Jonathan Glass jonathan.glass at ibb.gatech.edu
Wed May 21 19:31:44 EDT 2003


Okay.  I've written two scripts to read a nessus scan report, gather the
IP addresses, parse the dhcpd log file and obtain the MAC address.  The
2nd script then calls a 3rd script to check 5 managed switches to
determine into which port that computer is plugged.  This works reasonably
well, if just a bit slow.

My question is this:
When I call my Perl::Telnet script, I do so in a for loop, seen here:
------script2.sh------
for i in `cut -f 2 -d " " test-macs.txt | sed s/\:/\-/g`
do
echo $i
  for j in `seq 250 253`
  do
  echo 111.222.333.$j
  /home/jglass/perl/test-telnet.pl 111.222.333.$j "$i"
 done
done
-----end script2.sh---

The "test-telnet.pl" script returns the following output:

--------output--------

Location        VLAN ID Permanent
Unit 1 Port 25     1       No

------end output------
The output literally has a blank line, the Location & Unit line, then a
closing blank line, courtesy of the network equipment.

Each managed switch has 4 units and 24 ports.  If it returns "Port 25"
then I know it is on another switch.  How can I check 4 lines of input
(from stdout) for "Port 25", and if I see it, then I move to the next
switch, and if I don't, then I know either (a) the machine is not online,
or (b) it is online and it is on "Unit x port y" where y<25.  Any tips?  I
can do this when I can control the output to a single line, and use "cut",
but I'm at a loss as to how to capture multiple lines of input, parse it,
then output only what I want.  Help!

Thanks
-- 
Jonathan Glass
System Support Specialist II
Institute for Bioengineering & Biosciences (IBB)



_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale





More information about the Ale mailing list