Hi,
I'm stuck on using an array to determine the out come of a foreach loop.
The script is below.
------------------------------------------------------------------------------------------------------------
#!/usr/bin/perl
#
@conditions = ("NET", "eth");
$hostname = (`/bin/hostname`);
$logfile = "/var/log/messages";
$output = "/root/bin/output.txt";
open(OUTPUT, ">>", $output) or die $!;
open(LOGFILE, "<", $logfile) or die $!;
foreach $condition (@conditions) {
print "\n";
print "$condition detected on $hostname";
print
"=========================================================================\n";
foreach $line (<LOGFILE>) {
if ($line =~ /$condition/) {
print $line;
}
}
}
close(OUTPUT);
if ( -s $output) {
system(`/bin/mail -s \"$condition for \${HOSTNAME}\"
wpfonten...@cox.net < $output`);
unlink $output;
}
else {
unlink $output;
}
close(LOGFILE);
And the output is here
------------------------------------------------------------------------------------------------------------
NET detected on web.fontenotshome.local
=========================================================================
May 4 11:23:12 web kernel: NET: Registered protocol family 16
May 4 11:23:12 web kernel: NET: Registered protocol family 2
May 4 11:23:12 web kernel: NET: Registered protocol family 1
May 4 11:23:12 web kernel: NET: Registered protocol family 17
May 4 11:23:12 web kernel: NET: Registered protocol family 10
May 4 11:23:12 web kernel: Netfilter messages via NETLINK v0.30.
May 4 11:23:12 web kernel: NET: Registered protocol family 31
May 4 11:23:12 web kernel: Removing netfilter NETLINK layer.
May 4 11:23:12 web kernel: Netfilter messages via NETLINK v0.30.
May 4 11:23:12 web kernel: Removing netfilter NETLINK layer.
May 4 11:23:12 web kernel: Netfilter messages via NETLINK v0.30.
eth detected on web.fontenotshome.local
=========================================================================
The problem I have is I'm not getting the entries for eth. If I put
change this
@conditions = ("NET", "eth");
to this
@conditions = ("eth", "NET");
I get this
eth detected on web.fontenotshome.local
=========================================================================
May 4 11:23:12 web kernel: device eth0 entered promiscuous mode
May 4 11:23:12 web kernel: device eth0 left promiscuous mode
NET detected on web.fontenotshome.local
=========================================================================
I'm sure has a simple fix but it's wiping my tail right now...
Thanks for any help
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/