[ale] Bash Prompt Programming Question
James P. Kinney III
jkinney at localnetsolutions.com
Wed May 21 20:02:54 EDT 2003
On Wed, 2003-05-21 at 19:31, Jonathan Glass wrote:
> 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
if {
> '/home/jglass/perl/test-telnet.pl 111.222.333.$j "$i" | grep -c "Port 25"' > 0 }
do stuff here
fi
> 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!
Double check my syntax. I may have merged bash, perl and python.
>
> Thanks
--
James P. Kinney III \Changing the mobile computing world/
CEO & Director of Engineering \ one Linux user /
Local Net Solutions,LLC \ at a time. /
770-493-8244 \.___________________________./
http://www.localnetsolutions.com
GPG ID: 829C6CA7 James P. Kinney III (M.S. Physics) <jkinney at localnetsolutions.com>
Fingerprint = 3C9E 6366 54FC A3FE BA4D 0659 6190 ADC3 829C 6CA7
This is a digitally signed message part
More information about the Ale
mailing list