summaryrefslogtreecommitdiff
path: root/eg/scan/scan_messages
blob: 5aa45ff1021aa331163c2aafb5798c3e9d88aeb3 (plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/usr/bin/perl -P

# $Header: scan_messages,v 4.0 91/03/20 01:13:01 lwall Locked $

# This prints out extraordinary console messages.  You'll need to customize.

chdir('/usr/adm/private/memories') || die "Can't cd to memories: $!\n";

$maxpos = `cat oldmsgs 2>&1`;

#if defined(mc300) || defined(mc500) || defined(mc700)
open(Msgs, '/dev/null') || die "scan_messages: can't open messages";
#else
open(Msgs, '/usr/adm/messages') || die "scan_messages: can't open messages";
#endif

($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
   $blksize,$blocks) = stat(Msgs);

if ($size < $maxpos) {		# Did somebody truncate messages file?
    $maxpos = 0;
}

seek(Msgs,$maxpos,0);		# Start where we left off last time.

while (<Msgs>) {
    s/\[(\d+)\]/#/ && s/$1/#/g;
#ifdef vax
    $_ =~ s/[A-Z][a-z][a-z] +\w+ +[0-9:]+ +\w+ +//;
    next if /root@.*:/;
    next if /^vmunix: 4.3 BSD UNIX/;
    next if /^vmunix: Copyright/;
    next if /^vmunix: avail mem =/;
    next if /^vmunix: SBIA0 at /;
    next if /^vmunix: disk ra81 is/;
    next if /^vmunix: dmf. at uba/;
    next if /^vmunix: dmf.:.*asynch/;
    next if /^vmunix: ex. at uba/;
    next if /^vmunix: ex.: HW/;
    next if /^vmunix: il. at uba/;
    next if /^vmunix: il.: hardware/;
    next if /^vmunix: ra. at uba/;
    next if /^vmunix: ra.: media/;
    next if /^vmunix: real mem/;
    next if /^vmunix: syncing disks/;
    next if /^vmunix: tms/;
    next if /^vmunix: tmscp. at uba/;
    next if /^vmunix: uba. at /;
    next if /^vmunix: uda. at /;
    next if /^vmunix: uda.: unit . ONLIN/;
    next if /^vmunix: .*buffers containing/;
    next if /^syslogd: .*newslog/;
#endif
    next if /unknown service/;
    next if /^\.\.\.$/;
    if (/^[A-Z][a-z][a-z] [ 0-9][0-9] [ 0-9][0-9]:[0-9][0-9]/) {
	$pfx = '';
	next;
    }
    next if /^[ \t]*$/;
    next if /^[ 0-9]*done$/;
    if (/^A/) {
	next if /^Accounting [sr]/;
    }
    elsif (/^C/) {
	next if /^Called from/;
	next if /^Copyright/;
    }
    elsif (/^E/) {
	next if /^End traceback/;
	next if /^Ethernet address =/;
    }
    elsif (/^K/) {
	next if /^KERNEL MODE/;
    }
    elsif (/^R/) {
	next if /^Rebooting Unix/;
    }
    elsif (/^S/) {
	next if /^Sun UNIX 4\.2 Release/;
    }
    elsif (/^W/) {
	next if /^WARNING: clock gained/;
    }
    elsif (/^a/) {
	next if /^arg /;
	next if /^avail mem =/;
    }
    elsif (/^b/) {
	next if /^bwtwo[0-9] at /;
    }
    elsif (/^c/) {
	next if /^cgone[0-9] at /;
	next if /^cdp[0-9] at /;
	next if /^csr /;
    }
    elsif (/^d/) {
	next if /^dcpa: init/;
	next if /^done$/;
	next if /^dts/;
	next if /^dump i\/o error/;
	next if /^dumping to dev/;
	next if /^dump succeeded/;
	$pfx = '*' if /^dev = /;
    }
    elsif (/^e/) {
	next if /^end \*\*/;
	next if /^error in copy/;
    }
    elsif (/^f/) {
	next if /^found /;
    }
    elsif (/^i/) {
	next if /^ib[0-9] at /;
	next if /^ie[0-9] at /;
    }
    elsif (/^l/) {
	next if /^le[0-9] at /;
    }
    elsif (/^m/) {
	next if /^mem = /;
	next if /^mt[0-9] at /;
	next if /^mti[0-9] at /;
	$pfx = '*' if /^mode = /;
    }
    elsif (/^n/) {
	next if /^not found /;
    }
    elsif (/^p/) {
	next if /^page map /;
	next if /^pi[0-9] at /;
	$pfx = '*' if /^panic/;
    }
    elsif (/^q/) {
	next if /^qqq /;
    }
    elsif (/^r/) {
	next if /^read  /;
	next if /^revarp: Requesting/;
	next if /^root [od]/;
    }
    elsif (/^s/) {
	next if /^sc[0-9] at /;
	next if /^sd[0-9] at /;
	next if /^sd[0-9]: </;
	next if /^si[0-9] at /;
	next if /^si_getstatus/;
	next if /^sk[0-9] at /;
	next if /^skioctl/;
	next if /^skopen/;
	next if /^skprobe/;
	next if /^skread/;
	next if /^skwrite/;
	next if /^sky[0-9] at /;
	next if /^st[0-9] at /;
	next if /^st0:.*load/;
	next if /^stat1 = /;
	next if /^syncing disks/;
	next if /^syslogd: going down on signal 15/;
    }
    elsif (/^t/) {
	next if /^timeout [0-9]/;
	next if /^tm[0-9] at /;
	next if /^tod[0-9] at /;
	next if /^tv [0-9]/;
	$pfx = '*' if /^trap address/;
    }
    elsif (/^u/) {
	next if /^unit nsk/;
	next if /^use one of/;
	$pfx = '' if /^using/;
	next if /^using [0-9]+ buffers/;
    }
    elsif (/^x/) {
	next if /^xy[0-9] at /;
	next if /^write [0-9]/;
	next if /^xy[0-9]: </;
	next if /^xyc[0-9] at /;
    }
    elsif (/^y/) {
	next if /^yyy [0-9]/;
    }
    elsif (/^z/) {
	next if /^zs[0-9] at /;
    }
    $pfx = '*' if /^[a-z]+:$/;
    s/pid [0-9]+: //;
    if (/last message repeated ([0-9]+) time/) {
	$seen{$last} += $1;
	next;
    }
    s/^/$pfx/ if $pfx;
    unless ($seen{$_}++) {
	push(@seen,$_);
    }
    $last = $_;
}
$max = tell(Msgs);

open(tmp,'|sort >oldmsgs.tmp') || die "Can't create tmp file: $!\n";
while ($_ = pop(@seen)) {
    print tmp $_;
}
close(tmp);
open(tmp,'oldmsgs.tmp') || die "Can't reopen tmp file: $!\n";
while (<tmp>) {
    if (/^nd:/) {
	next if $seen{$_} < 20;
    }
    if (/NFS/) {
	next if $seen{$_} < 20;
    }
    if (/no carrier/) {
	next if $seen{$_} < 20;
    }
    if (/silo overflow/) {
	next if $seen{$_} < 20;
    }
    print $seen{$_},":\t",$_;
}

print `rm -f oldmsgs.tmp 2>&1; echo $max > oldmsgs 2>&1`;