1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
May 08 01:16:17 user.crit 192.178.168.15 May 7 23:16:17 rfp: 0074388084 ***** MAIN: connect OMM: Connection timed out
May 08 01:17:52 user.crit 192.178.168.15 May 7 23:17:52 rfp: 0074407091 ***** MAIN: connect OMM: Connection refused
May 08 09:20:00 daemon.info 192.178.168.15 May 8 07:20:00 snmpd[2306]: NET-SNMP version 5.1.2
May 08 11:35:10 daemon.info 192.178.168.15 May 8 09:35:11 init: starting pid 2318, tty '/dev/null': '/sbin/shutdown'
May 08 11:35:10 user.info 192.178.168.15 May 8 09:35:11 shutdown: running /sbin/shutdown
May 08 11:35:13 daemon.info 192.178.168.15 May 8 09:35:14 init: The system is going down NOW!
May 08 11:35:13 daemon.info 192.178.168.15 May 8 09:35:14 init: Sending SIGTERM to all processes
May 08 11:38:44 user.info 192.178.168.15 Nov 30 00:00:08 kernel: br0: port 1(eth0) entering forwarding state
May 08 11:38:44 user.info 192.178.168.15 Nov 30 00:00:08 kernel: br0: topology change detected, propagating
May 08 11:38:45 authpriv.info 192.178.168.15 Nov 30 00:00:09 dropbear[150]: Not backgrounding
May 08 11:38:45 daemon.info 192.178.168.15 Nov 30 00:00:09 init: starting pid 162, tty '/dev/null': '/opt/rfpm/rfpm'
May 08 11:38:45 user.notice 192.178.168.15 Nov 30 00:00:09 rfp: 0000002133 ! MAIN: Starting iprfp ...
May 08 11:38:45 user.notice 192.178.168.15 Nov 30 00:00:09 rfpm: 0000002139 ! MAIN: Starting rfpm ...
May 08 11:38:46 user.notice 192.178.168.15 Nov 30 00:00:10 rfp: 0000002349 ! MAIN: starting RFP application
May 08 11:38:48 user.notice 192.178.168.15 Nov 30 00:00:12 /etc/sysconfig/B20network: added default gateway
May 08 11:38:50 user.info 192.178.168.15 Nov 30 00:00:14 M20sntpc: starting sntpc
May 08 11:38:50 user.notice 192.178.168.15 Nov 30 00:00:14 sntpc: 0000003167 ** MAIN: sntp client started
May 08 11:38:50 user.notice 192.178.168.15 May 8 09:38:51 sntpc: 0000003181 ** MAIN: local clock set to Tue May 8 09:38:51 UTC 2012, offset was 392549916.323315
May 08 11:38:53 user.info 192.178.168.15 May 8 09:38:53 wlan: Initialized /var/run/wlan//storage_file (no data)
May 08 11:38:53 daemon.info 192.178.168.15 May 8 09:38:53 init: reloading /etc/inittab
May 08 11:39:06 daemon.info 192.178.168.15 May 8 09:39:06 snmpd[357]: NET-SNMP version 5.1.2
May 08 11:39:35 user.warn 192.178.168.15 May 8 09:39:35 kernel: WLAN driver starting
May 08 11:39:41 user.info 192.178.168.15 May 8 09:39:41 kernel: WLAN driver UP & RUNNING
May 08 11:39:41 user.info 192.178.168.15 May 8 09:39:41 kernel: device wlan0 entered promiscuous mode
May 08 11:39:41 user.info 192.178.168.15 May 8 09:39:41 kernel: br0: port 2(wlan0) entering learning state
May 08 11:39:42 user.info 192.178.168.15 May 8 09:39:42 kernel: br0: port 2(wlan0) entering forwarding state
May 08 11:39:42 user.info 192.178.168.15 May 8 09:39:42 kernel: br0: topology change detected, propagating
May 08 17:21:31 daemon.info 192.178.168.15 May 8 15:21:31 snmpd[357]: Received TERM or STOP signal... shutting down...
May 08 17:21:56 user.crit 192.178.168.15 May 8 15:21:56 rfp: 0004120191 ***** MAIN: connect OMM: Connection refused
May 08 17:21:56 user.crit 192.178.168.15 May 8 15:21:56 rfp: 0004120209 ***** MAIN: ; version = ''; type = RFP 42; capabilities = 3fc)
May 08 17:21:57 daemon.info 192.178.168.15 May 8 15:21:57 snmpd[19095]: NET-SNMP version 5.1.2
May 08 17:22:23 user.warn 192.178.168.15 May 8 15:22:23 kernel: WLAN driver starting
May 08 17:22:29 user.info 192.178.168.15 May 8 15:22:29 kernel: WLAN driver UP & RUNNING
May 08 17:22:29 user.info 192.178.168.15 May 8 15:22:29 kernel: device wlan0 entered promiscuous mode
May 08 17:22:29 user.info 192.178.168.15 May 8 15:22:29 kernel: br0: port 2(wlan0) entering learning state
May 08 17:22:30 user.info 192.178.168.15 May 8 15:22:30 kernel: br0: port 2(wlan0) entering forwarding state
May 08 17:22:30 user.info 192.178.168.15 May 8 15:22:30 kernel: br0: topology change detected, propagating
1 2
# alle Zeilen, die denString "WLAN" NICHT enthalten my @array = grep { index($_, "WLAN") < 0 } <$HANDLE>;
$ grep -v "WLAN\|UND\|ODER\|ANDERE\|UNINTERESSANTE\|STRINGS" logdatei > logdatei.cleaned
1 2 3 4 5 6 7 8 9 10 11
my $syslog_datei = "/var/log/syslog"; my $nicht_verwenden_regex = qr(WLAN); my @data; open (my $fh, "<", $syslog_datei) or die $!; while (my $line = <$fh>) { push @data, $line if $line !~ $nicht_verwenden_regex; } close $fh or die $!;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/perl -w
########################################
# Modules
use strict; # parameter Definition before use them
####################################
# modules
#######################################
# Paramet Definition
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$ydat,$isdst);
my ($jahr,$monat,$tag,$Xzeit,$Xdatum);
my $ct=1; # counter parameter
my $lines; # line parameter
my @data1 =("");
my $kw1="user.alert";
my $kw2="user.crit";
my $kw3="user.err";
my $ukw1="WLAN";
##################
# main programm
system("clear"); # Refresh the terminal
####################
# Time procedure
($sec,$min,$hour,$mday,$mon,$year,$wday,$ydat,$isdst)=localtime(); # Get TimeStamp-Elements
$jahr=$year;$monat=$mon+1;$tag=$mday;$jahr=$year;
$jahr=$year +1900; # Set the Year
if (length($monat) == 1){$monat="0$monat";} # Fillup the number amount
if(length($tag) == 1){ $tag="0$tag";}
if(length($hour) == 1){ $hour="0$hour";}
if(length($min) == 1){ $min="0$min";}
if(length($sec) == 1){ $sec="0$sec";}
#$Xdatum=$tag.".".$monat.".".$jahr;
$Xdatum=$tag.".".$monat;
$Xzeit=$hour.":".$min;
#########################
# Logfile analysis
open(InFile,$ARGV[0])or die $!; # read Inputfile
open(OutFile,">/home/cohama/SysLog/$Xdatum._SysLog_PTA-SIP.log")or die $!;
while ($lines = <InFile>) {
switch($lines){
case 1: =~ m{$kw1} {push(@data1,$lines);break; # read File line per line
case 2: =~ m{$kw2} {push(@data1,$lines);break;
case 3: =~ m{$kw3} {push(@data1,$lines);break;
}
#################################################
}
print "Store2File \n";
print OutFile @data1;
print "Close the files \n";
close(InFile);close(OutFile); # write Array 2 File
1 2 3
my $regex = qr{WLAN|UND|ANDERES|UNINTERESSANTES}; #my @clean_data = grep { ! $regex } @data; # so nicht! my @clean_data = grep { ! m/$regex/ } @data;
QuoteStarting in Perl 5.14, a "^" (caret or circumflex accent) immediately after the "?" is a shorthand equivalent to "d-imsx".
Flags (except "d") may follow the caret to override it. But a minus sign is not legal with it.
1 2 3
my @data = grep{ ! /$myfilters/ } @data1; # oder my @data = grep{ $_ !~ $myfilters } @data1;
@data = grep{$_ !~ $myfilters } @data1;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
my $kw1="user.alert"; my $kw2="user.crit"; my $kw3="user.err"; my $ukw1="WLAN"; #.... if ( $lines !~ /\Q$ukw1\E/ and ( $lines =~ /\Q$kw1\E/ or $lines =~ /\Q$kw2\E/ or $lines =~ /\Q$kw3\E/ ) ) #....