logcheck.pl
1.65 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/perl
#
# script to parse output log and determine presence
# and/or absence of output to TRACE address.
#
# when all specified conditions are met, exits normally.
# Otherwise, exits with return value of 1.
#
# usage:
#
# logcheck.pl [-p <output[,<times>]] [-n <output>] <logfile> <trace_reg>
#
# where:
#
# -p <output[,<times>[+]]>
# Will insure the TRACE output value <output> has occurred.
# Optionally, will verify <output> occurs exactly <times> times.
# If the + is present (i.e., -p 2+), will verify instead that
# <output> occurs at least <times> times.
#
# -n <output>
# Insure the TRACE output value <output> does NOT occur.
#
# <logfile>
# Name of log file to parse.
#
# <trace_reg>
# Address used for TRACE output
#
use Getopt::Std;
getopts("p:n:");
if ($opt_p != 0){
($present_string, $present_times) = split(/,/, $opt_p);
}
$plus = 0;
$temp = $present_times;
if (chop($temp) eq "+") {
$plus = 1;
$present_times = $temp;
}
$present_count = 0;
open(logfile, "@ARGV[0]") || die "Cannot open log file @ARGV[0].\n";
while ($line = <logfile>) {
if (($line =~ /@ARGV[1]/) && ($line =~ /cbus/)) {
$checkline = 1;
}
elsif ($checkline == 1){
if ($present_string ne "" && $line =~ /$present_string/) {
$present_count += 1;
}
elsif ($opt_n ne "" && $line =~ /$opt_n/) {
exit(1);
}
$checkline = 0;
}
}
close(logfile);
if ($present_times ne "") {
if ($plus == 0) {
if ($present_count != $present_times){
exit(1);
}
}
else {
if ($present_count < $present_times){
exit(1);
}
}
}
elsif ($opt_p != 0 && $present_count < 1){
exit(1);
}
exit(0);