Print this page
Bump Apache dependency to Apache 2
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/logadm/tester
+++ new/usr/src/cmd/logadm/tester
1 1 #!/usr/bin/perl -w
2 2 #
3 3 # CDDL HEADER START
4 4 #
5 5 # The contents of this file are subject to the terms of the
6 6 # Common Development and Distribution License (the "License").
7 7 # You may not use this file except in compliance with the License.
8 8 #
9 9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 # or http://www.opensolaris.org/os/licensing.
11 11 # See the License for the specific language governing permissions
12 12 # and limitations under the License.
13 13 #
14 14 # When distributing Covered Code, include this CDDL HEADER in each
15 15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 # If applicable, add the following below this CDDL HEADER, with the
17 17 # fields enclosed by brackets "[]" replaced with your own identifying
18 18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 19 #
20 20 # CDDL HEADER END
21 21 #
22 22 #
23 23 # Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 #
25 25 #
26 26 # tester - run logadm tests
27 27 #
28 28 # requires a <bindir> argument to say where the various logadm
29 29 # binaries live (conftest, globtest, kwtest, luttest, optstest, and
30 30 # logadm itself).
31 31 #
32 32 # to run all the tests:
33 33 # tester [-f] <bindir>
34 34 #
35 35 # to run just a few tests, given their names:
36 36 # tester [-f] <bindir> globtest1 luttest1
37 37 #
38 38 # to setup a test and stop so you can run it by hand:
39 39 # tester [-f] -s globtest1 <bindir>
40 40 #
41 41 # tester will tell you what tmp directory it created for
42 42 # the test. to run it, cd there and run:
43 43 # sh runtest
44 44 # to check the results, run:
45 45 # sh checktest
46 46 #
47 47 # -f means "fast" -- without it, watchmalloc(3MALLOC) is setup for
48 48 # each test and they run a zillion times slower and produce core
49 49 # dumps when malloc/free problems are detected.
50 50 #
51 51 $watchmalloc=1; # default is to use watchmalloc
52 52 ${ENV} = "/bin";
53 53 umask 002;
54 54
55 55 # list of tests we run by default
56 56 @tests = (
57 57 "conftest1",
58 58 "conftest2",
59 59 "globtest1",
60 60 "globtest2",
61 61 "kwtest1",
62 62 "kwtest2",
63 63 "luttest1",
64 64 "optstest1",
65 65 "optstest2",
66 66 "logadmV1",
67 67 "logadmV2",
68 68 "logadmr",
69 69 "logadmw",
70 70 "logadm1",
71 71 "logadm1c",
72 72 "logadm2",
73 73 "logadm3",
74 74 "logadm4",
75 75 "logadm5",
76 76 "logadm6",
77 77 "logadm7",
78 78 "logadm8",
79 79 "logadm9",
80 80 "logadm9d",
81 81 "logadm10",
82 82 "logadm11",
83 83 "logadm12",
84 84 "logadm13",
85 85 "logadm14",
86 86 "logadm15",
87 87 "logadm16",
88 88 "logadm17",
89 89 "logadm18",
90 90 "logadm19",
91 91 "logadm20",
92 92 );
93 93
94 94 use Getopt::Std;
95 95 use File::Find;
96 96
97 97 $usage_summary = '[-s test-name] [-d dir] bindir [test-name...]';
98 98 $usage_getopts = 'fd:s:';
99 99 %usage = (
100 100 d=>'use dir for tests rather than creating one in /tmp',
101 101 s=>'setup only, do not run test');
102 102
103 103 # spew usage message, plus any given message, and exit
104 104 sub usage {
105 105 my $msg = shift;
106 106
107 107 if ($msg) {
108 108 chomp $msg;
109 109 warn "$0: $msg\n" if $msg;
110 110 }
111 111 warn "Usage: $0 $usage_summary\n";
112 112 foreach (sort keys %usage) {
113 113 warn " -$_ $usage{$_}\n";
114 114 }
115 115 exit 1;
116 116 }
117 117
118 118 #
119 119 # basic argument processing
120 120 #
121 121 $myname = $0;
122 122 $myname =~ s/.*\///; # just show last component in error mesages
123 123 getopts($usage_getopts) or usage;
124 124 $bindir = shift or usage;
125 125 usage("$bindir does not exist") unless -d $bindir;
126 126 usage("cannot list more than one test with -s option") if $opt_s && @ARGV;
127 127 @tests = @ARGV if @ARGV;
128 128 print "Fast mode\n" if $opt_f;
129 129 $watchmalloc = 0 if $opt_f;
130 130
131 131 $mydir=`pwd`;
132 132 chomp $mydir;
133 133
134 134 $dir = $opt_d;
135 135 $dir = "/tmp/logadmtest$$" unless $dir = $opt_d;
136 136
137 137 if (!-d $dir) {
138 138 mkdir $dir, 0777 or die "$myname: mkdir $dir: $!\n";
139 139 $needrmdir = 1;
140 140 }
141 141
142 142 chdir $dir or die "$myname: $dir: $!\n";
143 143
144 144 # common commands in runtest by tests
145 145 if ($watchmalloc) {
146 146 $envsetup =
147 147 "HOME=$dir export HOME; " .
148 148 "LD_PRELOAD=watchmalloc.so.1 export LD_PRELOAD; " .
149 149 "MALLOC_DEBUG=RW export MALLOC_DEBUG";
150 150 } else {
151 151 $envsetup = "HOME=$dir export HOME; ";
152 152 }
153 153
154 154 $| = 1; # a.k.a. setbuf(stdout, NULL)
155 155
156 156 if ($opt_s) {
157 157 #
158 158 # just setup the test, explain how to use it, and exit
159 159 #
160 160 $testname = $opt_s;
161 161 eval "&$opt_s";
162 162 die "$myname: ERROR: $@" if $@;
163 163 print "$myname: $testname setup complete, to run, cd to:\n";
164 164 print " $dir\n";
165 165 print "and run the command:\n";
166 166 print " sh runtest\n";
167 167 print "to check the results, run the command:\n";
168 168 print " sh checktest\n";
169 169 exit 0;
170 170 } else {
171 171 #
172 172 # run all the tests
173 173 #
174 174 foreach (@tests) {
175 175 $testname = $_;
176 176 print "Running $testname...";
177 177 eval "&$_";
178 178 if ($@) {
179 179 print " SETUP FAILURE\n";
180 180 print STDERR "$myname: ERROR: $@";
181 181 exit 1;
182 182 }
183 183 eval "runner('runtest')";
184 184 if ($@) {
185 185 print " RUNTEST FAILURE\n";
186 186 print STDERR "$myname: ERROR: $@";
187 187 print STDERR "results captured in directory $dir\n";
188 188 print STDERR " or use: $myname -s $testname $bindir\n";
189 189 print STDERR " to do a fresh setup of this test.\n";
190 190 exit 1;
191 191 }
192 192 eval "runner('checktest', '-x', '> checktest.out 2>&1')";
193 193 if ($@) {
194 194 print " CHECKTEST FAILURE\n";
195 195 print STDERR "$myname: ERROR: $@";
196 196 print STDERR "results captured in file $dir/checktest.out\n";
197 197 print STDERR " or use: $myname -s $testname $bindir\n";
198 198 print STDERR " to do a fresh setup of this test.\n";
199 199 exit 1;
200 200 }
201 201 print "pass\n";
202 202 # sanity...
203 203 die "unexpected dir $dir" unless $dir =~ m,/.+/,;
204 204 system("/bin/rm -rf $dir/*");
205 205 }
206 206 }
207 207
208 208 # if we were the ones who created $dir, remove it
209 209 if ($needrmdir) {
210 210 chdir $mydir;
211 211 rmdir $dir || die "$myname: rmdir $dir: $!\n";
212 212 }
213 213
214 214 exit 0;
215 215
216 216 #
217 217 # run a shell script and check for failure
218 218 #
219 219 # the shell scripts generated by this program always "exec" the binary
220 220 # under test so checking here are for exit code, signals, and core dump
221 221 # is actually checking the program under test and not /bin/sh
222 222 #
223 223 sub runner {
224 224 my ($cmd, $prefix, $suffix) = (@_, '', '');
225 225
226 226 my $fullcmd = "/bin/sh $prefix $cmd $suffix";
227 227 my $rc = 0xffff & system("$fullcmd");
228 228
229 229 if ($rc == 0) {
230 230 return; # cmd completed normally
231 231 } elsif ($rc == 0xff00) {
232 232 die "command \"$cmd\" failed: $!\n";
233 233 } elsif (($rc & 0xff) == 0) {
234 234 $rc >>= 8;
235 235 die "command \"$cmd\" exit $rc\n";
236 236 } else {
237 237 my $coremsg;
238 238 $coremsg = " (core dumped)" if ($rc & 0x80);
239 239 $rc &= ~0x80;
240 240 die "command \"$cmd\" signal $rc$coremsg\n" ;
241 241 }
242 242 }
243 243
244 244 #
245 245 # set_file(filename [, contents]) -- create a file, optionally with contents
246 246 #
247 247 sub set_file {
248 248 my $file = shift;
249 249 my $contents = shift;
250 250
251 251 open SF, ">$file" or die "create \"$file\": $!\n";
252 252 print SF $contents if defined($contents);
253 253 close SF;
254 254 }
255 255
256 256 #############
257 257 #############
258 258 ############# THE TESTS START AFTER HERE...
259 259 #############
260 260 #############
261 261
262 262 # common setup step -- create a testfile.conf
263 263 sub set_testconffile {
264 264 my $fname = shift;
265 265 $fname = 'testfile.conf' unless defined($fname);
266 266
267 267 set_file($fname, <<'EOF');
268 268 #
269 269 # logadm.conf
270 270 #
271 271 # Default settings for system log file management.
272 272 # The -w option to logadm(1M) is the preferred way to write to this file,
273 273 # but if you do edit it by hand, use "logadm -V" to check it for errors.
274 274 #
275 275 # The format of lines in this file is:
276 276 # <logname> <options>
277 277 # For each logname listed here, the default options to logadm
278 278 # are given. Options given on the logadm command line override
279 279 # the defaults contained in this file.
280 280 #
↓ open down ↓ |
280 lines elided |
↑ open up ↑ |
281 281 # logadm typically runs early every morning via an entry in
282 282 # root's crontab (see crontab(1)).
283 283 #
284 284 /var/adm/messages -C 4 -P 'Thu Nov 1 16:56:42 2001' -a 'kill -HUP `cat /var/run/syslog.pid`'
285 285 /var/cron/log -s 512k -t /var/cron/olog
286 286 /var/lp/logs/lpsched -C 2 -N -t '$file.$N'
287 287 #
288 288 # The entry below is used by turnacct(1M)
289 289 #
290 290 /var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
291 -apache -C 24 -a '/usr/apache/bin/apachectl graceful' -p 1m -t '/var/apache/old-logs/$basename.%Y-%m' '/var/apache/logs/*{access,error}_log'
291 +apache -C 24 -a '/usr/apache2/2.2/bin/apachectl graceful' -p 1m -t '/var/apache2/2.2/old-logs/$basename.%Y-%m' '/var/apache2/2.2/logs/*{access,error}_log'
292 292 /var/log/syslog -C 8 -P 'Thu Nov 1 09:16:38 2001' -a 'kill -HUP `cat /var/run/syslog.pid`'
293 -/var/apache/logs/access_log -P 'Thu Nov 1 08:27:56 2001'
294 -/var/apache/logs/error_log -P 'Thu Nov 1 08:27:56 2001'
295 -/var/apache/logs/suexec_log -P 'Thu Nov 1 08:27:56 2001'
296 -/var/apache/logs/mod_jserv.log -P 'Thu Nov 1 08:27:56 2001'
297 -/var/apache/logs/jserv.log -P 'Thu Nov 1 08:27:56 2001'
293 +/var/apache2/2.2/logs/access_log -P 'Thu Nov 1 08:27:56 2001'
294 +/var/apache2/2.2/logs/error_log -P 'Thu Nov 1 08:27:56 2001'
295 +/var/apache2/2.2/logs/suexec_log -P 'Thu Nov 1 08:27:56 2001'
296 +/var/apache2/2.2/logs/mod_jserv.log -P 'Thu Nov 1 08:27:56 2001'
297 +/var/apache2/2.2/logs/jserv.log -P 'Thu Nov 1 08:27:56 2001'
298 298 EOF
299 299 }
300 300
301 301
302 302 ###########################################################################
303 303 #
304 304 # conftest1 -- minimal basic test of the conf.c code
305 305 #
306 306 ###########################################################################
307 307 sub conftest1 {
308 308 set_testconffile;
309 309
310 310 set_file('checktest', <<'EOF');
311 311 [ -s std.err ] && { cat std.err; exit 1; }
312 312 /bin/sed '/^conffile <testfile.conf>:$/d' <std.out >sed.out
313 313 exec /bin/diff testfile.conf sed.out
314 314 EOF
315 315
316 316 set_file('runtest', <<"EOF");
317 317 # test "conftest1"
318 318 $envsetup
319 319 exec $bindir/conftest testfile.conf >std.out 2>std.err
320 320 EOF
321 321 }
322 322
323 323 ###########################################################################
324 324 #
325 325 # conftest2 -- error path through conf.c
326 326 #
327 327 ###########################################################################
328 328 sub conftest2 {
329 329 set_file('testfile.conf', 'line fragment');
330 330
331 331 set_file('std.err.expect', <<'EOF');
332 332 conftest: Warning: file testfile.conf doesn't end with newline, last line ignored.
333 333 EOF
334 334
335 335 set_file('checktest', <<'EOF');
336 336 exec /bin/diff std.err.expect std.err
337 337 EOF
338 338
339 339 set_file('runtest', <<"EOF");
340 340 # test "conftest2"
341 341 $envsetup
342 342 $bindir/conftest testfile.conf >std.out 2>std.err || exit 0
343 343 exit 1
344 344 EOF
345 345 }
346 346
347 347 ###########################################################################
348 348 #
349 349 # globtest1 -- minimal basic test of the glob.c code
350 350 #
351 351 ###########################################################################
352 352 sub globtest1 {
353 353 set_file('fileBname12');
354 354 sleep 2; # ensure above name is odler than below name
355 355 set_file('fileAname12');
356 356 set_file('fileAname1');
357 357 set_file('fileAname3');
358 358 set_file('fileAname5');
359 359 set_file('fileAname7');
360 360 set_file('fileAname9');
361 361 set_file('fileAname11');
362 362 set_file('fileBname0');
363 363 set_file('fileBname2');
364 364 set_file('fileBname4');
365 365 set_file('fileBname6');
366 366 set_file('fileBname8');
367 367 set_file('fileBname10');
368 368 mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
369 369 mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
370 370 mkdir 'dir3', 0777 or die "mkdir dir3: $!\n";
371 371 mkdir 'dir1/dirA', 0777 or die "mkdir dir1/dirA: $!\n";
372 372 mkdir 'dir1/dirB', 0777 or die "mkdir dir1/dirB: $!\n";
373 373 mkdir 'dir1/dirC', 0777 or die "mkdir dir1/dirC: $!\n";
374 374 mkdir 'dir2/dirA', 0777 or die "mkdir dir2/dirA: $!\n";
375 375 mkdir 'dir2/dirB', 0777 or die "mkdir dir2/dirB: $!\n";
376 376 mkdir 'dir2/dirC', 0777 or die "mkdir dir2/dirC: $!\n";
377 377 set_file('dir1/fileAname1');
378 378 set_file('dir1/fileAname2');
379 379 set_file('dir1/fileAname3');
380 380 set_file('dir1/fileAname4');
381 381 set_file('dir1/fileAname5');
382 382 set_file('dir1/fileBname1');
383 383 set_file('dir1/fileBname2');
384 384 set_file('dir1/fileBname3');
385 385 set_file('dir1/fileBname4');
386 386 set_file('dir1/fileBname5');
387 387 # supply some varying sizes to produce different total size values
388 388 set_file('dir1/dirA/fileAname4', '4444');
389 389 sleep 2; # ensure above file is oldest in dirA
390 390 set_file('dir1/dirA/fileAname1', '1');
391 391 set_file('dir1/dirA/fileAname2', '22');
392 392 set_file('dir1/dirA/fileAname3', '333');
393 393 set_file('dir1/dirA/fileAname5', '55555');
394 394 set_file('dir1/dirA/fileBname1', '1');
395 395 set_file('dir1/dirA/fileBname2', '22');
396 396 set_file('dir1/dirA/fileBname3', '333');
397 397 set_file('dir1/dirA/fileBname4', '4444');
398 398 set_file('dir1/dirA/fileBname5', '55555');
399 399 set_file('dir1/dirB/fileAname1', '1');
400 400 set_file('dir1/dirB/fileAname2', '22');
401 401 set_file('dir1/dirB/fileAname3', '333');
402 402 set_file('dir1/dirB/fileAname4', '4444');
403 403 set_file('dir1/dirB/fileAname5', '55555');
404 404 set_file('dir1/dirB/fileBname1', '1');
405 405 set_file('dir1/dirB/fileBname2', '22');
406 406 set_file('dir1/dirB/fileBname3', '333');
407 407 set_file('dir1/dirB/fileBname4', '4444');
408 408 set_file('dir1/dirB/fileBname5', '55555');
409 409 set_file('dir1/dirC/fileAname10', '12345678901');
410 410 set_file('dir1/dirC/fileAname20', '123456789022');
411 411 set_file('dir1/dirC/fileAname30', '1234567890333');
412 412 set_file('dir1/dirC/fileAname40', '12345678904444');
413 413 set_file('dir1/dirC/fileAname50', '123456789055555');
414 414 set_file('dir1/dirC/fileBname10', '12345678901');
415 415 set_file('dir1/dirC/fileBname20', '123456789022');
416 416 set_file('dir1/dirC/fileBname30', '1234567890333');
417 417 set_file('dir1/dirC/fileBname40', '12345678904444');
418 418 set_file('dir1/dirC/fileBname50', '123456789055555');
419 419
420 420 set_file('std.out.expect', <<'EOF');
421 421 <file{A,B,C}name*>:
422 422 <./fileAname12>
423 423 <./fileAname1>
424 424 <./fileAname3>
425 425 <./fileAname5>
426 426 <./fileAname7>
427 427 <./fileAname9>
428 428 <./fileAname11>
429 429 <./fileBname12>
430 430 <./fileBname0>
431 431 <./fileBname2>
432 432 <./fileBname4>
433 433 <./fileBname6>
434 434 <./fileBname8>
435 435 <./fileBname10>
436 436 total size: 0
437 437 oldest <./fileBname12>
438 438 oldest <./fileBname8>
439 439 oldest <./fileBname6>
440 440 oldest <./fileBname4>
441 441 oldest <./fileBname2>
442 442 oldest <./fileBname10>
443 443 oldest <./fileBname0>
444 444 oldest <./fileAname9>
445 445 oldest <./fileAname7>
446 446 oldest <./fileAname5>
447 447 oldest <./fileAname3>
448 448 oldest <./fileAname12>
449 449 oldest <./fileAname11>
450 450 oldest <./fileAname1>
451 451 <file{A,B,C}name>:
452 452 <fileAname>
453 453 <fileBname>
454 454 <fileCname>
455 455 total size: 0
456 456 oldest <fileCname>
457 457 oldest <fileBname>
458 458 oldest <fileAname>
459 459 <dir1/dirA/file*>:
460 460 <./dir1/dirA/fileAname4>
461 461 <./dir1/dirA/fileAname1>
462 462 <./dir1/dirA/fileAname2>
463 463 <./dir1/dirA/fileAname3>
464 464 <./dir1/dirA/fileAname5>
465 465 <./dir1/dirA/fileBname1>
466 466 <./dir1/dirA/fileBname2>
467 467 <./dir1/dirA/fileBname3>
468 468 <./dir1/dirA/fileBname4>
469 469 <./dir1/dirA/fileBname5>
470 470 total size: 30
471 471 oldest <./dir1/dirA/fileAname4>
472 472 oldest <./dir1/dirA/fileBname5>
473 473 oldest <./dir1/dirA/fileBname4>
474 474 oldest <./dir1/dirA/fileBname3>
475 475 oldest <./dir1/dirA/fileBname2>
476 476 oldest <./dir1/dirA/fileBname1>
477 477 oldest <./dir1/dirA/fileAname5>
478 478 oldest <./dir1/dirA/fileAname3>
479 479 oldest <./dir1/dirA/fileAname2>
480 480 oldest <./dir1/dirA/fileAname1>
481 481 <dir[13]/[e-z]*>:
482 482 <./dir1/fileAname1>
483 483 <./dir1/fileAname2>
484 484 <./dir1/fileAname3>
485 485 <./dir1/fileAname4>
486 486 <./dir1/fileAname5>
487 487 <./dir1/fileBname1>
488 488 <./dir1/fileBname2>
489 489 <./dir1/fileBname3>
490 490 <./dir1/fileBname4>
491 491 <./dir1/fileBname5>
492 492 total size: 0
493 493 oldest <./dir1/fileBname5>
494 494 oldest <./dir1/fileBname4>
495 495 oldest <./dir1/fileBname3>
496 496 oldest <./dir1/fileBname2>
497 497 oldest <./dir1/fileBname1>
498 498 oldest <./dir1/fileAname5>
499 499 oldest <./dir1/fileAname4>
500 500 oldest <./dir1/fileAname3>
501 501 oldest <./dir1/fileAname2>
502 502 oldest <./dir1/fileAname1>
503 503 <dir?/dir[AC]/fileBname[2-9]>:
504 504 <./dir1/dirA/fileBname2>
505 505 <./dir1/dirA/fileBname3>
506 506 <./dir1/dirA/fileBname4>
507 507 <./dir1/dirA/fileBname5>
508 508 total size: 14
509 509 oldest <./dir1/dirA/fileBname5>
510 510 oldest <./dir1/dirA/fileBname4>
511 511 oldest <./dir1/dirA/fileBname3>
512 512 oldest <./dir1/dirA/fileBname2>
513 513 <file[A-Z]n.*e([0-9]+)$0>:
514 514 <./fileBname12>
515 515 <./fileAname12>
516 516 <./fileAname1>
517 517 <./fileAname3>
518 518 <./fileAname5>
519 519 <./fileAname7>
520 520 <./fileAname9>
521 521 <./fileAname11>
522 522 <./fileBname0>
523 523 <./fileBname2>
524 524 <./fileBname4>
525 525 <./fileBname6>
526 526 <./fileBname8>
527 527 <./fileBname10>
528 528 total size: 0
529 529 oldest <./fileBname12>
530 530 oldest <./fileAname12>
531 531 oldest <./fileAname11>
532 532 oldest <./fileBname10>
533 533 oldest <./fileAname9>
534 534 oldest <./fileBname8>
535 535 oldest <./fileAname7>
536 536 oldest <./fileBname6>
537 537 oldest <./fileAname5>
538 538 oldest <./fileBname4>
539 539 oldest <./fileAname3>
540 540 oldest <./fileBname2>
541 541 oldest <./fileAname1>
542 542 oldest <./fileBname0>
543 543 EOF
544 544
545 545 set_file('checktest', <<'EOF');
546 546 [ -s std.err ] && { cat std.err; exit 1; }
547 547 exec /bin/diff std.out.expect std.out
548 548 EOF
549 549
550 550 $testglobs='\'file{A,B,C}name*\' \'file{A,B,C}name\' \'dir1/dirA/file*\' \'dir[13]/[e-z]*\' \'dir?/dir[AC]/fileBname[2-9]\' -r \'file[A-Z]n.*e([0-9]+)$0\'';
551 551
552 552 set_file('runtest', <<"EOF");
553 553 # test "globtest1"
554 554 $envsetup
555 555 exec $bindir/globtest $testglobs >std.out 2>std.err
556 556 EOF
557 557 }
558 558
559 559 ###########################################################################
560 560 #
561 561 # globtest2 -- error path through glob.c
562 562 #
563 563 ###########################################################################
564 564 sub globtest2 {
565 565 set_file('std.err.expect', <<'EOF');
566 566 globtest: Error: Missing }
567 567 EOF
568 568
569 569 set_file('checktest', <<'EOF');
570 570 exec /bin/diff std.err.expect std.err
571 571 EOF
572 572
573 573 set_file('runtest', <<"EOF");
574 574 # test "globtest2"
575 575 $envsetup
576 576 $bindir/globtest 'hello{there' >std.out 2>std.err || exit 0
577 577 exit 1
578 578 EOF
579 579 }
580 580
581 581 ###########################################################################
582 582 #
583 583 # kwtest1 -- minimal basic test of the kw.c code
584 584 #
585 585 ###########################################################################
586 586 sub kwtest1 {
587 587 $domainname = `/bin/domainname`; chomp $domainname;
588 588 $isa = `/bin/uname -p`; chomp $isa;
589 589 $platform = `/bin/uname -i`; chomp $platform;
590 590 $nodename = `/bin/uname -n`; chomp $nodename;
591 591 $machine = `/bin/uname -m`; chomp $machine;
592 592 $release = `/bin/uname -r`; chomp $release;
593 593 # /bin/zonename is in SUNWzoneu and so may not be present
594 594 if (-f "/bin/zonename") {
595 595 $zonename = `/bin/zonename`; chomp $zonename;
596 596 } else {
597 597 $zonename = "global";
598 598 }
599 599 $secondblob=<<'EOF';
600 600 expand<$file.$n> n -1 hasn 1 result </var/log/syslog\.([0-9]+)$0>
601 601 expand<$file.$n> n 0 hasn 1 result </var/log/syslog.0>
602 602 expand<$file.$n> n 1 hasn 1 result </var/log/syslog.1>
603 603 expand<moose%d.$n> n -1 hasn 1 result <moose[0-9]+\.([0-9]+)$0>
604 604 expand<moose%d.$n> n 0 hasn 1 result <moose%d.0>
605 605 expand<moose%d.$n> n 1 hasn 1 result <moose%d.1>
606 606 expand</var/logs-%Y/moose-$isa$#porklips%d.$n> n -1 hasn 1 result </var/logs-[0-9]+/moose-ISAporklips[0-9]+\.([0-9]+)$0>
607 607 expand</var/logs-%Y/moose-$isa$#porklips%d.$n> n 0 hasn 1 result </var/logs-%Y/moose-ISAporklips%d.0>
608 608 expand</var/logs-%Y/moose-$isa$#porklips%d.$n> n 1 hasn 1 result </var/logs-%Y/moose-ISAporklips%d.1>
609 609 EOF
610 610 $percentd = `/bin/env TZ=UTC /bin/date +%d`; chomp $percentd;
611 611 $percentY = `/bin/env TZ=UTC /bin/date +%Y`; chomp $percentY;
612 612 $secondblob =~ s/%d/$percentd/mg;
613 613 $secondblob =~ s/%Y/$percentY/mg;
614 614 $secondblob =~ s/ISA/$isa/mg;
615 615 $utcenv = "TZ=UTC export TZ";
616 616 chomp $secondblob;
617 617 set_file('sed.out.expect', <<"EOF");
618 618 basename syslog
619 619 dirname /var/log
620 620 domain $domainname
621 621 file /var/log/syslog
622 622 home $dir
623 623 isa $isa
624 624 logname $ENV{LOGNAME}
625 625 machine $machine
626 626 nfile
627 627 nodename $nodename
628 628 platform $platform
629 629 release $release
630 630 user $ENV{USER}
631 631 zonename $zonename
632 632 $secondblob
633 633 EOF
634 634
635 635 set_file('checktest', <<'EOF');
636 636 [ -s std.err ] && { cat std.err; exit 1; }
637 637 /bin/sed -e '/^ *secs [0-9][0-9]*$/d'\
638 638 -e "s/%d/`/bin/env TZ=UTC /bin/date +%d`/g"\
639 639 -e "s/%Y/`/bin/env TZ=UTC /bin/date +%Y`/g"\
640 640 <std.out >sed.out
641 641 exec /bin/diff sed.out.expect sed.out
642 642 EOF
643 643
644 644 $kwtest='kwtest /var/log/syslog \'$file.$n\' \'moose%d.$n\' \'/var/logs-%Y/moose-$isa$#porklips%d.$n\'';
645 645 set_file('runtest', <<"EOF");
646 646 # test "kwtest1"
647 647 $envsetup
648 648 $utcenv
649 649 exec $bindir/$kwtest >std.out 2>std.err
650 650 EOF
651 651 }
652 652
653 653 ###########################################################################
654 654 #
655 655 # kwtest2 -- NULL environment variables test of the kw.c code
656 656 #
657 657 ###########################################################################
658 658 sub kwtest2 {
659 659 $domainname = `/bin/domainname`; chomp $domainname;
660 660 $isa = `/bin/uname -p`; chomp $isa;
661 661 $platform = `/bin/uname -i`; chomp $platform;
662 662 $nodename = `/bin/uname -n`; chomp $nodename;
663 663 $machine = `/bin/uname -m`; chomp $machine;
664 664 $release = `/bin/uname -r`; chomp $release;
665 665 # /bin/zonename is in SUNWzoneu and so may not be present
666 666 if (-f "/bin/zonename") {
667 667 $zonename = `/bin/zonename`; chomp $zonename;
668 668 } else {
669 669 $zonename = "global";
670 670 }
671 671 $secondblob=<<'EOF';
672 672 expand<$file.$n> n -1 hasn 1 result </var/log/syslog\.([0-9]+)$0>
673 673 expand<$file.$n> n 0 hasn 1 result </var/log/syslog.0>
674 674 expand<$file.$n> n 1 hasn 1 result </var/log/syslog.1>
675 675 expand<moose%d.$n> n -1 hasn 1 result <moose[0-9]+\.([0-9]+)$0>
676 676 expand<moose%d.$n> n 0 hasn 1 result <moose%d.0>
677 677 expand<moose%d.$n> n 1 hasn 1 result <moose%d.1>
678 678 expand</var/logs-%Y/moose-$isa$#porklips%d.$n> n -1 hasn 1 result </var/logs-[0-9]+/moose-ISAporklips[0-9]+\.([0-9]+)$0>
679 679 expand</var/logs-%Y/moose-$isa$#porklips%d.$n> n 0 hasn 1 result </var/logs-%Y/moose-ISAporklips%d.0>
680 680 expand</var/logs-%Y/moose-$isa$#porklips%d.$n> n 1 hasn 1 result </var/logs-%Y/moose-ISAporklips%d.1>
681 681 EOF
682 682 $percentd = `/bin/env TZ=UTC /bin/date +%d`; chomp $percentd;
683 683 $percentY = `/bin/env TZ=UTC /bin/date +%Y`; chomp $percentY;
684 684 $secondblob =~ s/%d/$percentd/mg;
685 685 $secondblob =~ s/%Y/$percentY/mg;
686 686 $secondblob =~ s/ISA/$isa/mg;
687 687 chomp $secondblob;
688 688 set_file('sed.out.expect', <<"EOF");
689 689 basename syslog
690 690 dirname /var/log
691 691 domain $domainname
692 692 file /var/log/syslog
693 693 home
694 694 isa $isa
695 695 logname
696 696 machine $machine
697 697 nfile
698 698 nodename $nodename
699 699 platform $platform
700 700 release $release
701 701 user
702 702 zonename $zonename
703 703 $secondblob
704 704 EOF
705 705
706 706 set_file('checktest', <<'EOF');
707 707 [ -s std.err ] && { cat std.err; exit 1; }
708 708 /bin/sed -e '/^ *secs [0-9][0-9]*$/d'\
709 709 -e "s/%d/`/bin/env TZ=UTC /bin/date +%d`/g"\
710 710 -e "s/%Y/`/bin/env TZ=UTC /bin/date +%Y`/g"\
711 711 <std.out >sed.out
712 712 exec /bin/diff sed.out.expect sed.out
713 713 EOF
714 714
715 715 $kwtest='kwtest /var/log/syslog \'$file.$n\' \'moose%d.$n\' \'/var/logs-%Y/moose-$isa$#porklips%d.$n\'';
716 716 set_file('runtest', <<"EOF");
717 717 # test "kwtest2"
718 718 $envsetup
719 719 LOGNAME=
720 720 export LOGNAME
721 721 HOME=
722 722 export HOME
723 723 USER=
724 724 export USER
725 725 TZ=UTC
726 726 export TZ
727 727 exec $bindir/$kwtest >std.out 2>std.err
728 728 EOF
729 729 }
730 730
731 731 ###########################################################################
732 732 #
733 733 # luttest1 -- minimal basic test of the lut.c code
734 734 #
735 735 ###########################################################################
736 736 sub luttest1 {
737 737 set_file('std.out.expect', <<'EOF');
738 738 lut contains:
739 739 <fix> <NULL> (<NULL>)
740 740 <one> <two> (<two>)
741 741 <seven> <eight> (<eight>)
742 742 <six> <NULL> (<NULL>)
743 743 <three> <four> (<four>)
744 744 dup lut contains:
745 745 <fix> <NULL> (<NULL>)
746 746 <one> <two> (<two>)
747 747 <seven> <eight> (<eight>)
748 748 <six> <NULL> (<NULL>)
749 749 <three> <four> (<four>)
750 750 EOF
751 751
752 752 set_file('checktest', <<'EOF');
753 753 [ -s std.err ] && { cat std.err; exit 1; }
754 754 exec /bin/diff std.out.expect std.out
755 755 EOF
756 756
757 757 set_file('runtest', <<"EOF");
758 758 # test "luttest1"
759 759 $envsetup
760 760 exec $bindir/luttest one=two three=four fix six seven=eight >std.out 2>std.err
761 761 EOF
762 762 }
763 763
764 764 ###########################################################################
765 765 #
766 766 # optstest1 -- minimal basic test of the opts.c code
767 767 #
768 768 ###########################################################################
769 769 sub optstest1 {
770 770 $options="-a -b moose -c 1h -d 'Fri Nov 2 13:19:55 2001' -e 1k -f 2 one two three";
771 771 set_file('std.out.expect', <<"EOF");
772 772 options: $options
773 773 EOF
774 774
775 775 set_file('checktest', <<'EOF');
776 776 [ -s std.err ] && { cat std.err; exit 1; }
777 777 exec /bin/diff std.out.expect std.out
778 778 EOF
779 779
780 780 set_file('runtest', <<"EOF");
781 781 # test "optstest1"
782 782 $envsetup
783 783 exec $bindir/optstest $options >std.out 2>std.err
784 784 EOF
785 785 }
786 786
787 787 ###########################################################################
788 788 #
789 789 # optstest2 -- error path through opts.c code
790 790 #
791 791 ###########################################################################
792 792 sub optstest2 {
793 793 $options="-a -b -c 1h -d 'Fri Nov 2 13:19:55 2001' -e 1k -f 2 one two three";
794 794 set_file('std.err.expect', <<'EOF');
795 795 optstest: Error: Option 'b' requires an argument
796 796 optstest: Error: opts parsing failed
797 797 EOF
798 798
799 799 set_file('checktest', <<'EOF');
800 800 [ -s std.out ] && exit 1
801 801 exec /bin/diff std.err.expect std.err
802 802 EOF
803 803
804 804 set_file('runtest', <<"EOF");
805 805 # test "optstest2"
806 806 $envsetup
807 807 $bindir/optstest $options >std.out 2>std.err || exit 0
808 808 exit 1
809 809 EOF
810 810 }
811 811
812 812 ###########################################################################
813 813 #
814 814 # logadmV1 -- test of "logadm -V"
↓ open down ↓ |
507 lines elided |
↑ open up ↑ |
815 815 #
816 816 ###########################################################################
817 817 sub logadmV1 {
818 818 set_testconffile;
819 819
820 820 set_file('std.out.expect', <<'EOF');
821 821 /var/adm/messages -C 4 -P 'Thu Nov 1 16:56:42 2001' -a 'kill -HUP `cat /var/run/syslog.pid`'
822 822 /var/cron/log -s 512k -t /var/cron/olog
823 823 /var/lp/logs/lpsched -C 2 -N -t '$file.$N'
824 824 /var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
825 -apache -C 24 -a '/usr/apache/bin/apachectl graceful' -p 1m -t '/var/apache/old-logs/$basename.%Y-%m' '/var/apache/logs/*{access,error}_log'
825 +apache -C 24 -a '/usr/apache2/2.2/bin/apachectl graceful' -p 1m -t '/var/apache2/2.2/old-logs/$basename.%Y-%m' '/var/apache2/2.2/logs/*{access,error}_log'
826 826 /var/log/syslog -C 8 -P 'Thu Nov 1 09:16:38 2001' -a 'kill -HUP `cat /var/run/syslog.pid`'
827 -/var/apache/logs/access_log -P 'Thu Nov 1 08:27:56 2001'
828 -/var/apache/logs/error_log -P 'Thu Nov 1 08:27:56 2001'
829 -/var/apache/logs/suexec_log -P 'Thu Nov 1 08:27:56 2001'
830 -/var/apache/logs/mod_jserv.log -P 'Thu Nov 1 08:27:56 2001'
831 -/var/apache/logs/jserv.log -P 'Thu Nov 1 08:27:56 2001'
827 +/var/apache2/2.2/logs/access_log -P 'Thu Nov 1 08:27:56 2001'
828 +/var/apache2/2.2/logs/error_log -P 'Thu Nov 1 08:27:56 2001'
829 +/var/apache2/2.2/logs/suexec_log -P 'Thu Nov 1 08:27:56 2001'
830 +/var/apache2/2.2/logs/mod_jserv.log -P 'Thu Nov 1 08:27:56 2001'
831 +/var/apache2/2.2/logs/jserv.log -P 'Thu Nov 1 08:27:56 2001'
832 832 EOF
833 833
834 834 set_file('checktest', <<'EOF');
835 835 [ -s std.err ] && { cat std.err; exit 1; }
836 836 exec /bin/diff std.out.expect std.out
837 837 EOF
838 838
839 839 set_file('runtest', <<"EOF");
840 840 # test "logadmV1"
841 841 $envsetup
842 842 exec $bindir/logadm -f testfile.conf -F testfile.conf -V >std.out 2>std.err
843 843 EOF
844 844 }
845 845
846 846 ###########################################################################
847 847 #
848 848 # logadmV2 -- test of "logadm -V <entry>"
849 849 #
850 850 ###########################################################################
851 851 sub logadmV2 {
852 852 set_testconffile;
853 853
854 854 set_file('std.out.expect', <<'EOF');
855 855 /var/cron/log -s 512k -t /var/cron/olog
856 856 /var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
857 857 EOF
858 858
859 859 set_file('checktest', <<'EOF');
860 860 [ -s std.err ] && { cat std.err; exit 1; }
861 861 exec /bin/diff std.out.expect std.out
862 862 EOF
863 863
864 864 set_file('runtest', <<"EOF");
865 865 # test "logadmV2"
866 866 $envsetup
867 867 exec $bindir/logadm -f testfile.conf -F testfile.conf -V /var/cron/log /var/adm/pacct >std.out 2>std.err
868 868 EOF
869 869 }
870 870
871 871 ###########################################################################
872 872 #
873 873 # logadmr -- test of "logadm -r <entry>"
874 874 #
875 875 ###########################################################################
876 876 sub logadmr {
877 877 set_testconffile;
878 878 set_testconffile('testfile.conf.orig');
879 879
880 880 set_file('diff.out.expect', <<'EOF');
881 881 18d17
882 882 < /var/cron/log -s 512k -t /var/cron/olog
883 883 23d21
884 884 < /var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
885 885 EOF
886 886
887 887 set_file('checktest', <<'EOF');
888 888 [ -s std.err ] && { cat std.err; exit 1; }
889 889 /bin/diff testfile.conf.orig testfile.conf > diff.out
890 890 exec /bin/diff diff.out.expect diff.out
891 891 EOF
892 892
893 893 set_file('runtest', <<"EOF");
894 894 # test "logadmr"
895 895 $envsetup
896 896 exec $bindir/logadm -f testfile.conf -F testfile.conf -r /var/cron/log /var/adm/pacct >std.out 2>std.err
897 897 EOF
898 898 }
899 899
900 900 ###########################################################################
901 901 #
902 902 # logadmw -- test of "logadm -w <entry>"
903 903 #
904 904 ###########################################################################
905 905 sub logadmw {
906 906 set_testconffile;
907 907 set_testconffile('testfile.conf.orig');
908 908
909 909 set_file('diff.out.expect', <<'EOF');
910 910 30a31
911 911 > moose -C 20 -a moose_after_cmd -g pig -m 664 -o cow -p never /moose/file
912 912 EOF
913 913
914 914 set_file('checktest', <<'EOF');
915 915 [ -s std.err ] && { cat std.err; exit 1; }
916 916 /bin/diff testfile.conf.orig testfile.conf > diff.out
917 917 exec /bin/diff diff.out.expect diff.out
918 918 EOF
919 919
920 920 set_file('runtest', <<"EOF");
921 921 # test "logadmw"
922 922 $envsetup
923 923 exec $bindir/logadm -f testfile.conf -F testfile.conf -w moose -C 20 -a moose_after_cmd -g pig -m 664 -o cow -p never /moose/file >std.out 2>std.err
924 924 EOF
925 925 }
926 926
927 927 ###########################################################################
928 928 #
929 929 # logadm1 -- minimal basic test of logadm rotation
930 930 #
931 931 ###########################################################################
932 932 sub logadm1 {
933 933 set_file('logfile', 'initially logfile');
934 934 set_file('logfile.0', 'initially logfile.0');
935 935 my ($stdev, $stino, $stmode, $stnlink, $stuid, $stgid, $strdev,
936 936 $stsize, $statime, $stmtime, $stctime, $stblksize, $stblocks) =
937 937 lstat 'logfile' or die "lstat logfile: $!\n";
938 938
939 939 set_file('checktest', <<"EOF");
940 940 [ -s std.err ] && { cat std.err; exit 1; }
941 941 [ -s std.out ] && exit 1
942 942 [ -s logfile ] && exit 1
943 943 [ -f logfile.0 ] || exit 1
944 944 [ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
945 945 [ "`/bin/ls -i logfile.0 | /bin/awk '{ print \$1; }'`" = "$stino" ] || exit 1
946 946 [ -f logfile.1 ] || exit 1
947 947 [ "xinitially logfile.0" = "x`/bin/cat logfile.1`" ] || exit 1
948 948 exit 0
949 949 EOF
950 950
951 951 set_file('runtest', <<"EOF");
952 952 # test "logadm1"
953 953 $envsetup
954 954 exec $bindir/logadm -f /dev/null -p now logfile >std.out 2>std.err
955 955 EOF
956 956 }
957 957
958 958 ###########################################################################
959 959 #
960 960 # logadm1c -- same as logadm1 but with -c option
961 961 #
962 962 ###########################################################################
963 963 sub logadm1c {
964 964 set_file('logfile', 'initially logfile');
965 965 set_file('logfile.0', 'initially logfile.0');
966 966 my ($stdev, $stino, $stmode, $stnlink, $stuid, $stgid, $strdev,
967 967 $stsize, $statime, $stmtime, $stctime, $stblksize, $stblocks) =
968 968 lstat 'logfile' or die "lstat logfile: $!\n";
969 969
970 970 set_file('checktest', <<"EOF");
971 971 [ -s std.err ] && { cat std.err; exit 1; }
972 972 [ -s std.out ] && exit 1
973 973 [ -s logfile ] && exit 1
974 974 [ -f logfile.0 ] || exit 1
975 975 [ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
976 976 [ "`/bin/ls -i logfile.0 | /bin/awk '{ print \$1; }'`" = "$stino" ] && exit 1
977 977 [ -f logfile.1 ] || exit 1
978 978 [ "xinitially logfile.0" = "x`/bin/cat logfile.1`" ] || exit 1
979 979 exit 0
980 980 EOF
981 981
982 982 set_file('runtest', <<"EOF");
983 983 # test "logadm1c"
984 984 $envsetup
985 985 exec $bindir/logadm -f /dev/null -p now -c logfile >std.out 2>std.err
986 986 EOF
987 987 }
988 988
989 989 ###########################################################################
990 990 #
991 991 # logadm2 -- minimal basic test of logadm expiration
992 992 #
993 993 ###########################################################################
994 994 sub logadm2 {
995 995 set_file('logfile', 'initially logfile');
996 996 set_file('logfile.0', 'initially logfile.0');
997 997 set_file('logfile.1', 'initially logfile.1');
998 998
999 999 set_file('checktest', <<'EOF');
1000 1000 [ -s std.err ] && { cat std.err; exit 1; }
1001 1001 [ -s std.out ] && exit 1
1002 1002 [ -s logfile ] && exit 1
1003 1003 [ -f logfile.0 ] || exit 1
1004 1004 [ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
1005 1005 [ -f logfile.1 ] || exit 1
1006 1006 [ "xinitially logfile.0" = "x`/bin/cat logfile.1`" ] || exit 1
1007 1007 [ -f logfile.2 ] && exit 1
1008 1008 exit 0
1009 1009 EOF
1010 1010
1011 1011 set_file('runtest', <<"EOF");
1012 1012 # test "logadm2"
1013 1013 $envsetup
1014 1014 exec $bindir/logadm -f /dev/null -p now logfile -C2 >std.out 2>std.err
1015 1015 EOF
1016 1016 }
1017 1017
1018 1018 ###########################################################################
1019 1019 #
1020 1020 # logadm3 -- minimal basic test of logadm pre/post-commands
1021 1021 #
1022 1022 ###########################################################################
1023 1023 sub logadm3 {
1024 1024 set_file('logfile', 'initially logfile');
1025 1025 set_file('logfile.0', 'initially logfile.0');
1026 1026 set_file('logfile.1', 'initially logfile.1');
1027 1027
1028 1028 set_file('checktest', <<'EOF');
1029 1029 [ -s std.err ] && { cat std.err; exit 1; }
1030 1030 [ -s std.out ] && exit 1
1031 1031 [ -s logfile ] && exit 1
1032 1032 [ -f logfile.0 ] || exit 1
1033 1033 [ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
1034 1034 [ -f logfile.1 ] || exit 1
1035 1035 [ "xinitially logfile.0" = "x`/bin/cat logfile.1`" ] || exit 1
1036 1036 [ -f logfile.2 ] && exit 1
1037 1037 [ -f pre.out ] || exit 1
1038 1038 [ "xpre-command-stuff" = "x`/bin/cat pre.out`" ] || exit 1
1039 1039 [ -f post.out ] || exit 1
1040 1040 [ "xpost-command-stuff" = "x`/bin/cat post.out`" ] || exit 1
1041 1041 exit 0
1042 1042 EOF
1043 1043
1044 1044 set_file('runtest', <<"EOF");
1045 1045 # test "logadm3"
1046 1046 $envsetup
1047 1047 exec $bindir/logadm -f /dev/null -p now logfile -C2 -b 'echo pre-command-stuff > pre.out' -a 'echo post-command-stuff > post.out' >std.out 2>std.err
1048 1048 EOF
1049 1049 }
1050 1050
1051 1051 ###########################################################################
1052 1052 #
1053 1053 # logadm4 -- test of -t template
1054 1054 #
1055 1055 ###########################################################################
1056 1056 sub logadm4 {
1057 1057 set_file('logfile', 'initially logfile');
1058 1058
1059 1059 set_file('checktest', <<'EOF');
1060 1060 [ -s std.err ] && { cat std.err; exit 1; }
1061 1061 [ -s std.out ] && exit 1
1062 1062 [ -s logfile ] && exit 1
1063 1063 TZ=UTC export TZ
1064 1064 d=`/bin/date +%d`
1065 1065 [ -f logfile.$d ] || exit 1
1066 1066 [ "xinitially logfile" = "x`/bin/cat logfile.$d`" ] || exit 1
1067 1067 exit 0
1068 1068 EOF
1069 1069
1070 1070 set_file('runtest', <<"EOF");
1071 1071 # test "logadm4"
1072 1072 $envsetup
1073 1073 exec $bindir/logadm -f /dev/null -p now logfile -t '\$file.\%d' >std.out 2>std.err
1074 1074 EOF
1075 1075 }
1076 1076
1077 1077 ###########################################################################
1078 1078 #
1079 1079 # logadm5 -- test of -R cmd and -E cmd
1080 1080 #
1081 1081 ###########################################################################
1082 1082 sub logadm5 {
1083 1083 set_file('logfile', 'initially logfile');
1084 1084 set_file('logfile.0', 'initially logfile.0');
1085 1085
1086 1086 set_file('cmd.out.expect', <<'EOF');
1087 1087 just rotated: initially logfile
1088 1088 just expired: initially logfile.0
1089 1089 EOF
1090 1090
1091 1091 set_file('checktest', <<'EOF');
1092 1092 [ -s std.err ] && { cat std.err; exit 1; }
1093 1093 [ -s std.out ] && exit 1
1094 1094 [ -s logfile ] && exit 1
1095 1095 [ -f logfile.0 ] || exit 1
1096 1096 [ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
1097 1097 [ -f logfile.1 ] || exit 1
1098 1098 [ "xinitially logfile.0" = "x`/bin/cat logfile.1`" ] || exit 1
1099 1099 exec /bin/diff cmd.out.expect cmd.out
1100 1100 EOF
1101 1101
1102 1102 set_file('runtest', <<"EOF");
1103 1103 # test "logadm5"
1104 1104 $envsetup
1105 1105 exec $bindir/logadm -f /dev/null -p now logfile -C1 -R 'echo just rotated: `/bin/cat \$file` >>cmd.out' -E 'echo just expired: `/bin/cat \$file` >>cmd.out' >std.out 2>std.err
1106 1106 EOF
1107 1107 }
1108 1108
1109 1109 ###########################################################################
1110 1110 #
1111 1111 # logadm6 -- test of -m, -o, -g
1112 1112 #
1113 1113 ###########################################################################
1114 1114 sub logadm6 {
1115 1115 set_file('logfile', 'initially logfile');
1116 1116
1117 1117 set_file('std.err.expect', <<'EOF');
1118 1118 logadm: Warning: command failed: /bin/chown _nonexistentuser_:_nonexistentgroup_ logfile
1119 1119 chown: unknown group id _nonexistentgroup_
1120 1120 EOF
1121 1121
1122 1122 set_file('checktest', <<'EOF');
1123 1123 [ -s std.err ] || exit 1;
1124 1124 [ -s std.out ] && exit 1
1125 1125 [ -s logfile ] && exit 1
1126 1126 [ -f logfile.0 ] || exit 1
1127 1127 [ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
1128 1128 [ "`/bin/ls -l logfile | /bin/awk '{ print $1; }'`" = "-r----x--x" ] || exit 1
1129 1129 exec /bin/diff std.err.expect std.err
1130 1130 EOF
1131 1131
1132 1132 set_file('runtest', <<"EOF");
1133 1133 # test "logadm6"
1134 1134 $envsetup
1135 1135 exec $bindir/logadm -f /dev/null -p now logfile -m 411 -o _nonexistentuser_ -g _nonexistentgroup_ >std.out 2>std.err
1136 1136 EOF
1137 1137 }
1138 1138
1139 1139 ###########################################################################
1140 1140 #
1141 1141 # logadm7 -- test running through a conffile
1142 1142 #
1143 1143 ###########################################################################
1144 1144 sub logadm7 {
1145 1145 mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
1146 1146 set_file('dir1/syslog', 'initially dir1/syslog');
1147 1147 set_file('dir1/syslog.0', 'initially dir1/syslog.0');
1148 1148 set_file('dir1/syslog.1', 'initially dir1/syslog.1');
1149 1149 set_file('dir1/syslog.2', 'initially dir1/syslog.2');
1150 1150 set_file('dir1/syslog.3', 'initially dir1/syslog.3');
1151 1151 set_file('dir1/syslog.4', 'initially dir1/syslog.4');
1152 1152 set_file('dir1/syslog.5', 'initially dir1/syslog.5');
1153 1153 set_file('dir1/syslog.6', 'initially dir1/syslog.6');
1154 1154 set_file('dir1/syslog.7', 'initially dir1/syslog.7');
1155 1155 mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
1156 1156 set_file('dir2/messages', 'initially dir2/messages');
1157 1157 set_file('dir2/messages.0', 'initially dir2/messages.0');
1158 1158 set_file('dir2/messages.1', 'initially dir2/messages.1');
1159 1159 set_file('dir2/messages.2', 'initially dir2/messages.2');
1160 1160 set_file('dir2/messages.3', 'initially dir2/messages.3');
1161 1161
1162 1162 set_file('logadm.conf', <<'EOF');
1163 1163 #
1164 1164 # logadm.conf
1165 1165 #
1166 1166 # this comment # has at least another #-sign in it #...
1167 1167 #
1168 1168 # Default settings for system log file management.
1169 1169 # The -w option to logadm(1M) is the preferred way to write to this file,
1170 1170 # but if you do edit it by hand, use "logadm -V" to check it for errors.
1171 1171 # but if you do edit it by hand, use "logadm -V" to check it for errors.
1172 1172 #
1173 1173 # The format of lines in this file is:
1174 1174 # <logname> <options>
1175 1175 # For each logname listed here, the default options to logadm
1176 1176 # are given. Options given on the logadm command line override
1177 1177 # the defaults contained in this file.
1178 1178 #
1179 1179 # logadm typically runs early every morning via an entry in
1180 1180 # root's crontab (see crontab(1)).
1181 1181 #
1182 1182 dir1/syslog -C 8 -a 'echo kill -HUP `cat /etc/syslog.pid` >> cmd.out'
1183 1183 dir2/messages -C 4 -a 'echo kill -HUP `cat /etc/syslog.pid` >> cmd.out'
1184 1184 #
1185 1185 # The entry below is used by turnacct(1M)
1186 1186 #
1187 1187 /var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
1188 1188 EOF
1189 1189
1190 1190 system("/bin/cp logadm.conf logadm.conf.orig");
1191 1191
1192 1192 $pid=`cat /etc/syslog.pid`;
1193 1193 chomp $pid;
1194 1194 set_file('cmd.out.expect', <<"EOF");
1195 1195 kill -HUP $pid
1196 1196 second kill -HUP $pid
1197 1197 EOF
1198 1198
1199 1199 set_file('sed.out.expect', <<'EOF');
1200 1200 # This file holds internal data for logadm(1M).
1201 1201 # Do not edit.
1202 1202 dir1/syslog
1203 1203 dir2/messages
1204 1204 EOF
1205 1205
1206 1206 set_file('checktest', <<'EOF');
1207 1207 [ -s std.err ] && { cat std.err; exit 1; }
1208 1208 [ -s std.out ] && exit 1
1209 1209 [ -s logadm.timestamps ] || exit 1
1210 1210 [ -s std.err2 ] && exit 1
1211 1211 [ -s std.out2 ] && exit 1
1212 1212 [ -s std.err3 ] && exit 1
1213 1213 [ -s std.out3 ] && exit 1
1214 1214 [ -s std.err4 ] && exit 1
1215 1215 [ -s std.out4 ] && exit 1
1216 1216 [ -f dir1/syslog ] || exit 1
1217 1217 [ "xsomething" = "x`/bin/cat dir1/syslog`" ] || exit 1
1218 1218 [ -f dir1/syslog.0 ] || exit 1
1219 1219 [ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
1220 1220 [ -f dir1/syslog.1 ] || exit 1
1221 1221 [ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
1222 1222 [ -f dir1/syslog.2 ] || exit 1
1223 1223 [ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
1224 1224 [ -f dir1/syslog.3 ] || exit 1
1225 1225 [ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
1226 1226 [ -f dir1/syslog.4 ] || exit 1
1227 1227 [ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
1228 1228 [ -f dir1/syslog.5 ] || exit 1
1229 1229 [ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
1230 1230 [ -f dir1/syslog.6 ] || exit 1
1231 1231 [ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
1232 1232 [ -f dir1/syslog.7 ] || exit 1
1233 1233 [ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
1234 1234 [ -f dir1/syslog.8 ] && exit 1
1235 1235
1236 1236 [ -s dir2/messages ] && exit 1
1237 1237 [ -f dir2/messages.0 ] || exit 1
1238 1238 [ "xsomething" = "x`/bin/cat dir2/messages.0`" ] || exit 1
1239 1239 [ -f dir2/messages.1 ] || exit 1
1240 1240 [ "xinitially dir2/messages" = "x`/bin/cat dir2/messages.1`" ] || exit 1
1241 1241 [ -f dir2/messages.2 ] || exit 1
1242 1242 [ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.2`" ] || exit 1
1243 1243 [ -f dir2/messages.3 ] || exit 1
1244 1244 [ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.3`" ] || exit 1
1245 1245 [ -f dir2/messages.4 ] && exit 1
1246 1246 /bin/sed "s/ -P '[^']*' *//" < logadm.timestamps > sed.out
1247 1247 /bin/diff sed.out.expect sed.out || exit 1
1248 1248 exec /bin/diff logadm.conf.orig logadm.conf
1249 1249 EOF
1250 1250
1251 1251 # first logadm call will rotate both syslog and messages
1252 1252 # second one won't because size is zero
1253 1253 # third one won't because of -P timestamps stored in conffile
1254 1254 # fourth one will do messages because of -p now on command line
1255 1255 set_file('runtest', <<"EOF");
1256 1256 # test "logadm7"
1257 1257 $envsetup
1258 1258 $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err || exit 1
1259 1259 $bindir/logadm -f logadm.conf -F logadm.timestamps dir1/syslog dir2/messages >std.out2 2>std.err2 || exit 1
1260 1260 echo something > dir1/syslog
1261 1261 echo something > dir2/messages
1262 1262 $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out3 2>std.err3 || exit 1
1263 1263 exec $bindir/logadm -f logadm.conf -F logadm.timestamps dir2/messages -p now -a 'echo second kill -HUP `cat /etc/syslog.pid` >> cmd.out' >std.out4 2>std.err4
1264 1264 EOF
1265 1265 }
1266 1266
1267 1267 ###########################################################################
1268 1268 #
1269 1269 # logadm8 -- test of -z
1270 1270 #
1271 1271 ###########################################################################
1272 1272 sub logadm8 {
1273 1273 mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
1274 1274 set_file('dir1/syslog', 'initially dir1/syslog');
1275 1275 set_file('dir1/syslog.0', 'initially dir1/syslog.0');
1276 1276 set_file('dir1/syslog.1', 'initially dir1/syslog.1');
1277 1277 set_file('dir1/syslog.2', 'initially dir1/syslog.2');
1278 1278 system("/bin/gzip dir1/syslog.2");
1279 1279 die "gzip dir1/syslog.2 didn't work\n" unless -f 'dir1/syslog.2.gz';
1280 1280 set_file('dir1/syslog.3', 'initially dir1/syslog.3');
1281 1281 system("/bin/gzip dir1/syslog.3");
1282 1282 die "gzip dir1/syslog.3 didn't work\n" unless -f 'dir1/syslog.3.gz';
1283 1283 set_file('dir1/syslog.4', 'initially dir1/syslog.4');
1284 1284 system("/bin/gzip dir1/syslog.4");
1285 1285 die "gzip dir1/syslog.4 didn't work\n" unless -f 'dir1/syslog.4.gz';
1286 1286 set_file('dir1/syslog.5', 'initially dir1/syslog.5');
1287 1287 system("/bin/gzip dir1/syslog.5");
1288 1288 die "gzip dir1/syslog.5 didn't work\n" unless -f 'dir1/syslog.5.gz';
1289 1289 set_file('dir1/syslog.6', 'initially dir1/syslog.6');
1290 1290 system("/bin/gzip dir1/syslog.6");
1291 1291 die "gzip dir1/syslog.6 didn't work\n" unless -f 'dir1/syslog.6.gz';
1292 1292 set_file('dir1/syslog.7', 'initially dir1/syslog.7');
1293 1293 system("/bin/gzip dir1/syslog.7");
1294 1294 die "gzip dir1/syslog.7 didn't work\n" unless -f 'dir1/syslog.7.gz';
1295 1295
1296 1296 set_file('checktest', <<'EOF');
1297 1297 [ -s std.err ] && { cat std.err; exit 1; }
1298 1298 [ -s std.out ] && exit 1
1299 1299 [ -f dir1/syslog ] || exit 1
1300 1300 [ -s dir1/syslog ] && exit 1
1301 1301 [ -f dir1/syslog.0 ] || exit 1
1302 1302 [ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
1303 1303 [ -f dir1/syslog.1 ] || exit 1
1304 1304 [ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
1305 1305 [ -f dir1/syslog.2.gz ] || exit 1
1306 1306 [ "xinitially dir1/syslog.1" = "x`/bin/gzcat dir1/syslog.2.gz`" ] || exit 1
1307 1307 [ -f dir1/syslog.3.gz ] || exit 1
1308 1308 [ "xinitially dir1/syslog.2" = "x`/bin/gzcat dir1/syslog.3.gz`" ] || exit 1
1309 1309 [ -f dir1/syslog.4.gz ] || exit 1
1310 1310 [ "xinitially dir1/syslog.3" = "x`/bin/gzcat dir1/syslog.4.gz`" ] || exit 1
1311 1311 [ -f dir1/syslog.5.gz ] || exit 1
1312 1312 [ "xinitially dir1/syslog.4" = "x`/bin/gzcat dir1/syslog.5.gz`" ] || exit 1
1313 1313 [ -f dir1/syslog.6.gz ] || exit 1
1314 1314 [ "xinitially dir1/syslog.5" = "x`/bin/gzcat dir1/syslog.6.gz`" ] || exit 1
1315 1315 [ -f dir1/syslog.7.gz ] || exit 1
1316 1316 [ "xinitially dir1/syslog.6" = "x`/bin/gzcat dir1/syslog.7.gz`" ] || exit 1
1317 1317 [ -f dir1/syslog.8 ] && exit 1
1318 1318 [ -f dir1/syslog.8.gz ] && exit 1
1319 1319 exit 0
1320 1320 EOF
1321 1321
1322 1322 set_file('runtest', <<"EOF");
1323 1323 # test "logadm8"
1324 1324 $envsetup
1325 1325 exec $bindir/logadm -f /dev/null dir1/syslog -z 2 -C 8 >std.out 2>std.err
1326 1326 EOF
1327 1327 }
1328 1328
1329 1329 ###########################################################################
1330 1330 #
1331 1331 # logadm9 -- test of age check
1332 1332 #
1333 1333 ###########################################################################
1334 1334 sub logadm9 {
1335 1335 mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
1336 1336 set_file('dir1/syslog', 'initially dir1/syslog');
1337 1337 set_file('dir1/syslog.0', 'initially dir1/syslog.0');
1338 1338 set_file('dir1/syslog.1', 'initially dir1/syslog.1');
1339 1339 set_file('dir1/syslog.2', 'initially dir1/syslog.2');
1340 1340 set_file('dir1/syslog.3', 'initially dir1/syslog.3');
1341 1341 set_file('dir1/syslog.4', 'initially dir1/syslog.4');
1342 1342 set_file('dir1/syslog.5', 'initially dir1/syslog.5');
1343 1343 set_file('dir1/syslog.6', 'initially dir1/syslog.6');
1344 1344 set_file('dir1/syslog.7', 'initially dir1/syslog.7');
1345 1345 set_file('dir1/notes', 'initially dir1/notes');
1346 1346 mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
1347 1347 set_file('dir2/messages', 'initially dir2/messages');
1348 1348 set_file('dir2/messages.0', 'initially dir2/messages.0');
1349 1349 set_file('dir2/messages.1', 'initially dir2/messages.1');
1350 1350 set_file('dir2/messages.2', 'initially dir2/messages.2');
1351 1351 set_file('dir2/messages.3', 'initially dir2/messages.3');
1352 1352 set_file('dir2/log', 'initially dir2/log');
1353 1353
1354 1354 $now = time;
1355 1355 $nowstr = gmtime($now);
1356 1356 # a week minus 30 seconds ago...
1357 1357 # technically not a full week, but the heuristic used by logadm
1358 1358 # should think this is "close enough" to a full week
1359 1359 $closetoweeksecs = $now - (60 * 60 * 24 * 7 - 30);
1360 1360 $closetoweek = gmtime($closetoweeksecs);
1361 1361 # a week minus six hours ago...
1362 1362 $lessthanweeksecs = $now - (60 * 60 * 24 * 7 - 60 * 60 * 6);
1363 1363 $lessthanweek = gmtime($lessthanweeksecs);
1364 1364
1365 1365 set_file('logadm.conf', <<"EOF");
1366 1366 # now: $nowstr is $now
1367 1367 # $closetoweek is $closetoweeksecs
1368 1368 dir1/syslog -C 8 -P '$closetoweek'
1369 1369 dir2/log -C 4
1370 1370 # $lessthanweek is $lessthanweeksecs
1371 1371 dir1/notes -C 2 -P '$lessthanweek'
1372 1372 dir2/messages -C 4
1373 1373 EOF
1374 1374 set_file('logadm.timestamps', <<"EOF");
1375 1375 dir2/log -P '$closetoweek'
1376 1376 dir2/messages -P '$lessthanweek'
1377 1377 EOF
1378 1378
1379 1379 set_file('sed.out.expect', <<"EOF");
1380 1380 # This file holds internal data for logadm(1M).
1381 1381 # Do not edit.
1382 1382 dir1/syslog
1383 1383 dir2/log
1384 1384 dir1/notes
1385 1385 dir2/messages
1386 1386 EOF
1387 1387
1388 1388 set_file('checktest', <<'EOF');
1389 1389 [ -s std.err ] && { cat std.err; exit 1; }
1390 1390 [ -s std.out ] && exit 1
1391 1391 [ -f dir1/syslog ] || exit 1
1392 1392 [ -s dir1/syslog ] && exit 1
1393 1393 [ -f dir1/syslog.0 ] || exit 1
1394 1394 [ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
1395 1395 [ -f dir1/syslog.1 ] || exit 1
1396 1396 [ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
1397 1397 [ -f dir1/syslog.2 ] || exit 1
1398 1398 [ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
1399 1399 [ -f dir1/syslog.3 ] || exit 1
1400 1400 [ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
1401 1401 [ -f dir1/syslog.4 ] || exit 1
1402 1402 [ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
1403 1403 [ -f dir1/syslog.5 ] || exit 1
1404 1404 [ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
1405 1405 [ -f dir1/syslog.6 ] || exit 1
1406 1406 [ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
1407 1407 [ -f dir1/syslog.7 ] || exit 1
1408 1408 [ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
1409 1409 [ -f dir1/syslog.8 ] && exit 1
1410 1410
1411 1411 [ -s dir1/notes ] || exit 1
1412 1412 [ "xinitially dir1/notes" = "x`/bin/cat dir1/notes`" ] || exit 1
1413 1413 [ -f dir1/notes.0 ] && exit 1
1414 1414
1415 1415 [ -f dir2/messages ] || exit 1
1416 1416 [ "xinitially dir2/messages" = "x`/bin/cat dir2/messages`" ] || exit 1
1417 1417 [ -f dir2/messages.0 ] || exit 1
1418 1418 [ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.0`" ] || exit 1
1419 1419 [ -f dir2/messages.1 ] || exit 1
1420 1420 [ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.1`" ] || exit 1
1421 1421 [ -f dir2/messages.2 ] || exit 1
1422 1422 [ "xinitially dir2/messages.2" = "x`/bin/cat dir2/messages.2`" ] || exit 1
1423 1423 [ -f dir2/messages.3 ] || exit 1
1424 1424 [ "xinitially dir2/messages.3" = "x`/bin/cat dir2/messages.3`" ] || exit 1
1425 1425 [ -f dir2/messages.4 ] && exit 1
1426 1426
1427 1427 [ -f dir2/log ] || exit 1
1428 1428 [ -s dir2/log ] && exit 1
1429 1429 [ -f dir2/log.0 ] || exit 1
1430 1430 [ "xinitially dir2/log" = "x`/bin/cat dir2/log.0`" ] || exit 1
1431 1431 [ -f dir2/log.1 ] && exit 1
1432 1432
1433 1433 /bin/sed "s/ -P '[^']*' *//" < logadm.timestamps > sed.out
1434 1434 /bin/diff sed.out.expect sed.out || exit 1
1435 1435 /bin/sed -n "s/ -P '[^']*' */<&>/p" < logadm.conf > sed.out
1436 1436 [ -s sed.out ] && exit 1
1437 1437 exit 0
1438 1438 EOF
1439 1439
1440 1440 set_file('runtest', <<"EOF");
1441 1441 # test "logadm9"
1442 1442 $envsetup
1443 1443 exec $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err
1444 1444 EOF
1445 1445 }
1446 1446
1447 1447 ###########################################################################
1448 1448 #
1449 1449 # logadm9d -- test of age check like logadm9, but age is a couple days
1450 1450 #
1451 1451 ###########################################################################
1452 1452 sub logadm9d {
1453 1453 mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
1454 1454 set_file('dir1/syslog', 'initially dir1/syslog');
1455 1455 set_file('dir1/syslog.0', 'initially dir1/syslog.0');
1456 1456 set_file('dir1/syslog.1', 'initially dir1/syslog.1');
1457 1457 set_file('dir1/syslog.2', 'initially dir1/syslog.2');
1458 1458 set_file('dir1/syslog.3', 'initially dir1/syslog.3');
1459 1459 set_file('dir1/syslog.4', 'initially dir1/syslog.4');
1460 1460 set_file('dir1/syslog.5', 'initially dir1/syslog.5');
1461 1461 set_file('dir1/syslog.6', 'initially dir1/syslog.6');
1462 1462 set_file('dir1/syslog.7', 'initially dir1/syslog.7');
1463 1463 mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
1464 1464 set_file('dir2/messages', 'initially dir2/messages');
1465 1465 set_file('dir2/messages.0', 'initially dir2/messages.0');
1466 1466 set_file('dir2/messages.1', 'initially dir2/messages.1');
1467 1467 set_file('dir2/messages.2', 'initially dir2/messages.2');
1468 1468 set_file('dir2/messages.3', 'initially dir2/messages.3');
1469 1469
1470 1470 $now = time;
1471 1471 $nowstr = gmtime($now);
1472 1472 # a day minus 30 seconds ago...
1473 1473 $closetodaysecs = $now - (60 * 60 * 24 - 30);
1474 1474 $closetoday = gmtime($closetodaysecs);
1475 1475 # a day minus six hours ago...
1476 1476 $lessthandaysecs = $now - (60 * 60 * 24 - 60 * 60 * 6);
1477 1477 $lessthanday = gmtime($lessthandaysecs);
1478 1478
1479 1479 set_file('logadm.conf', <<"EOF");
1480 1480 # now: $nowstr is $now
1481 1481 # $closetoday is $closetodaysecs
1482 1482 dir1/syslog -p 1d -C 8 -P '$closetoday'
1483 1483 # $lessthanday is $lessthandaysecs
1484 1484 dir2/messages -p 1d -C 4 -P '$lessthanday'
1485 1485 EOF
1486 1486
1487 1487 set_file('checktest', <<'EOF');
1488 1488 [ -s std.err ] && { cat std.err; exit 1; }
1489 1489 [ -s std.out ] && exit 1
1490 1490 [ -f dir1/syslog ] || exit 1
1491 1491 [ -s dir1/syslog ] && exit 1
1492 1492 [ -f dir1/syslog.0 ] || exit 1
1493 1493 [ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
1494 1494 [ -f dir1/syslog.1 ] || exit 1
1495 1495 [ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
1496 1496 [ -f dir1/syslog.2 ] || exit 1
1497 1497 [ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
1498 1498 [ -f dir1/syslog.3 ] || exit 1
1499 1499 [ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
1500 1500 [ -f dir1/syslog.4 ] || exit 1
1501 1501 [ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
1502 1502 [ -f dir1/syslog.5 ] || exit 1
1503 1503 [ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
1504 1504 [ -f dir1/syslog.6 ] || exit 1
1505 1505 [ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
1506 1506 [ -f dir1/syslog.7 ] || exit 1
1507 1507 [ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
1508 1508 [ -f dir1/syslog.8 ] && exit 1
1509 1509
1510 1510 [ -f dir2/messages ] || exit 1
1511 1511 [ "xinitially dir2/messages" = "x`/bin/cat dir2/messages`" ] || exit 1
1512 1512 [ -f dir2/messages.0 ] || exit 1
1513 1513 [ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.0`" ] || exit 1
1514 1514 [ -f dir2/messages.1 ] || exit 1
1515 1515 [ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.1`" ] || exit 1
1516 1516 [ -f dir2/messages.2 ] || exit 1
1517 1517 [ "xinitially dir2/messages.2" = "x`/bin/cat dir2/messages.2`" ] || exit 1
1518 1518 [ -f dir2/messages.3 ] || exit 1
1519 1519 [ "xinitially dir2/messages.3" = "x`/bin/cat dir2/messages.3`" ] || exit 1
1520 1520 [ -f dir2/messages.4 ] && exit 1
1521 1521 exit 0
1522 1522 EOF
1523 1523
1524 1524 set_file('runtest', <<"EOF");
1525 1525 # test "logadm9d"
1526 1526 $envsetup
1527 1527 exec $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err
1528 1528 EOF
1529 1529 }
1530 1530
1531 1531 ###########################################################################
1532 1532 #
1533 1533 # logadm10 -- test of size-based rotation check
1534 1534 #
1535 1535 ###########################################################################
1536 1536 sub logadm10 {
1537 1537 mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
1538 1538 set_file('dir1/syslog', 'initially dir1/syslogXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
1539 1539 set_file('dir1/syslog.0', 'initially dir1/syslog.0');
1540 1540 set_file('dir1/syslog.1', 'initially dir1/syslog.1');
1541 1541 set_file('dir1/syslog.2', 'initially dir1/syslog.2');
1542 1542 set_file('dir1/syslog.3', 'initially dir1/syslog.3');
1543 1543 set_file('dir1/syslog.4', 'initially dir1/syslog.4');
1544 1544 set_file('dir1/syslog.5', 'initially dir1/syslog.5');
1545 1545 set_file('dir1/syslog.6', 'initially dir1/syslog.6');
1546 1546 set_file('dir1/syslog.7', 'initially dir1/syslog.7');
1547 1547 mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
1548 1548 set_file('dir2/messages', 'initially dir2/messages');
1549 1549 set_file('dir2/messages.0', 'initially dir2/messages.0');
1550 1550 set_file('dir2/messages.1', 'initially dir2/messages.1');
1551 1551 set_file('dir2/messages.2', 'initially dir2/messages.2');
1552 1552 set_file('dir2/messages.3', 'initially dir2/messages.3');
1553 1553
1554 1554 set_file('logadm.conf', <<"EOF");
1555 1555 dir1/syslog -C 8 -s 30b
1556 1556 dir2/messages -C 4 -s 30b
1557 1557 EOF
1558 1558
1559 1559 set_file('checktest', <<'EOF');
1560 1560 [ -s std.err ] && { cat std.err; exit 1; }
1561 1561 [ -s std.out ] && exit 1
1562 1562 [ -f dir1/syslog ] || exit 1
1563 1563 [ -s dir1/syslog ] && exit 1
1564 1564 [ -f dir1/syslog.0 ] || exit 1
1565 1565 [ "xinitially dir1/syslogXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
1566 1566 [ -f dir1/syslog.1 ] || exit 1
1567 1567 [ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
1568 1568 [ -f dir1/syslog.2 ] || exit 1
1569 1569 [ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
1570 1570 [ -f dir1/syslog.3 ] || exit 1
1571 1571 [ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
1572 1572 [ -f dir1/syslog.4 ] || exit 1
1573 1573 [ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
1574 1574 [ -f dir1/syslog.5 ] || exit 1
1575 1575 [ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
1576 1576 [ -f dir1/syslog.6 ] || exit 1
1577 1577 [ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
1578 1578 [ -f dir1/syslog.7 ] || exit 1
1579 1579 [ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
1580 1580 [ -f dir1/syslog.8 ] && exit 1
1581 1581
1582 1582 [ -f dir2/messages ] || exit 1
1583 1583 [ "xinitially dir2/messages" = "x`/bin/cat dir2/messages`" ] || exit 1
1584 1584 [ -f dir2/messages.0 ] || exit 1
1585 1585 [ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.0`" ] || exit 1
1586 1586 [ -f dir2/messages.1 ] || exit 1
1587 1587 [ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.1`" ] || exit 1
1588 1588 [ -f dir2/messages.2 ] || exit 1
1589 1589 [ "xinitially dir2/messages.2" = "x`/bin/cat dir2/messages.2`" ] || exit 1
1590 1590 [ -f dir2/messages.3 ] || exit 1
1591 1591 [ "xinitially dir2/messages.3" = "x`/bin/cat dir2/messages.3`" ] || exit 1
1592 1592 [ -f dir2/messages.4 ] && exit 1
1593 1593 exit 0
1594 1594 EOF
1595 1595
1596 1596 set_file('runtest', <<"EOF");
1597 1597 # test "logadm10"
1598 1598 $envsetup
1599 1599 exec $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err
1600 1600 EOF
1601 1601 }
1602 1602
1603 1603 ###########################################################################
1604 1604 #
1605 1605 # logadm11 -- test of size-based expiration check
1606 1606 #
1607 1607 ###########################################################################
1608 1608 sub logadm11 {
1609 1609 mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
1610 1610 set_file('dir1/syslog', 'initially dir1/syslog');
1611 1611 set_file('dir1/syslog.0', 'initially dir1/syslog.0');
1612 1612 set_file('dir1/syslog.1', 'initially dir1/syslog.1');
1613 1613 set_file('dir1/syslog.2', 'initially dir1/syslog.2');
1614 1614 set_file('dir1/syslog.3', 'initially dir1/syslog.3');
1615 1615 set_file('dir1/syslog.4', 'initially dir1/syslog.4');
1616 1616 set_file('dir1/syslog.5', 'initially dir1/syslog.5');
1617 1617 set_file('dir1/syslog.6', 'initially dir1/syslog.6');
1618 1618 set_file('dir1/syslog.7', 'initially dir1/syslog.7');
1619 1619 mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
1620 1620 set_file('dir2/messages', 'initially dir2/messages');
1621 1621 set_file('dir2/messages.0', 'initially dir2/messages.0');
1622 1622 set_file('dir2/messages.1', 'initially dir2/messages.1');
1623 1623 set_file('dir2/messages.2', 'initially dir2/messages.2');
1624 1624 set_file('dir2/messages.3', 'initially dir2/messages.3');
1625 1625
1626 1626 set_file('logadm.conf', <<"EOF");
1627 1627 dir1/syslog -C 8 -s 30b -S 75b
1628 1628 dir2/messages -C 4 -s 30b -S 75b
1629 1629 EOF
1630 1630
1631 1631 set_file('checktest', <<'EOF');
1632 1632 [ -s std.err ] && { cat std.err; exit 1; }
1633 1633 [ -s std.out ] && exit 1
1634 1634 [ -f dir1/syslog ] || exit 1
1635 1635 [ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog`" ] || exit 1
1636 1636 [ -f dir1/syslog.0 ] || exit 1
1637 1637 [ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
1638 1638 [ -f dir1/syslog.1 ] || exit 1
1639 1639 [ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
1640 1640 [ -f dir1/syslog.2 ] || exit 1
1641 1641 [ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
1642 1642 [ -f dir1/syslog.3 ] && exit 1
1643 1643 [ -f dir1/syslog.4 ] && exit 1
1644 1644 [ -f dir1/syslog.5 ] && exit 1
1645 1645 [ -f dir1/syslog.6 ] && exit 1
1646 1646 [ -f dir1/syslog.7 ] && exit 1
1647 1647 [ -f dir1/syslog.8 ] && exit 1
1648 1648
1649 1649 [ -f dir2/messages ] || exit 1
1650 1650 [ "xinitially dir2/messages" = "x`/bin/cat dir2/messages`" ] || exit 1
1651 1651 [ -f dir2/messages.0 ] || exit 1
1652 1652 [ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.0`" ] || exit 1
1653 1653 [ -f dir2/messages.1 ] || exit 1
1654 1654 [ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.1`" ] || exit 1
1655 1655 [ -f dir2/messages.2 ] || exit 1
1656 1656 [ "xinitially dir2/messages.2" = "x`/bin/cat dir2/messages.2`" ] || exit 1
1657 1657 [ -f dir2/messages.3 ] && exit 1
1658 1658 [ -f dir2/messages.4 ] && exit 1
1659 1659 exit 0
1660 1660 EOF
1661 1661
1662 1662 set_file('runtest', <<"EOF");
1663 1663 # test "logadm11"
1664 1664 $envsetup
1665 1665 exec $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err
1666 1666 EOF
1667 1667 }
1668 1668
1669 1669 ###########################################################################
1670 1670 #
1671 1671 # logadm12 -- ENOENT error path
1672 1672 #
1673 1673 ###########################################################################
1674 1674 sub logadm12 {
1675 1675 set_file('std.err.expect', <<'EOF');
1676 1676 logadm: Warning: logfile: No such file or directory
1677 1677 EOF
1678 1678
1679 1679 set_file('checktest', <<"EOF");
1680 1680 [ -s std.out ] && exit 1
1681 1681 exec /bin/diff std.err.expect std.err
1682 1682 EOF
1683 1683
1684 1684 set_file('runtest', <<"EOF");
1685 1685 # test "logadm12"
1686 1686 $envsetup
1687 1687 exec $bindir/logadm -f /dev/null logfile >std.out 2>std.err
1688 1688 EOF
1689 1689 }
1690 1690
1691 1691 ###########################################################################
1692 1692 #
1693 1693 # logadm13 -- ENOENT error path with -N flag
1694 1694 #
1695 1695 ###########################################################################
1696 1696 sub logadm13 {
1697 1697 set_file('checktest', <<"EOF");
1698 1698 [ -s std.err ] && { cat std.err; exit 1; }
1699 1699 [ -s std.out ] && exit 1
1700 1700 exit 0
1701 1701 EOF
1702 1702
1703 1703 set_file('runtest', <<"EOF");
1704 1704 # test "logadm13"
1705 1705 $envsetup
1706 1706 exec $bindir/logadm -N -f /dev/null logfile >std.out 2>std.err
1707 1707 EOF
1708 1708 }
1709 1709
1710 1710 ###########################################################################
1711 1711 #
1712 1712 # logadm14 -- test of -n and -v flags
1713 1713 #
1714 1714 ###########################################################################
1715 1715 sub logadm14 {
1716 1716 mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
1717 1717 set_file('dir1/syslog', 'initially dir1/syslog');
1718 1718 set_file('dir1/syslog.0', 'initially dir1/syslog.0');
1719 1719 set_file('dir1/syslog.1', 'initially dir1/syslog.1');
1720 1720 set_file('dir1/syslog.2', 'initially dir1/syslog.2');
1721 1721 set_file('dir1/syslog.3', 'initially dir1/syslog.3');
1722 1722 set_file('dir1/syslog.4', 'initially dir1/syslog.4');
1723 1723 set_file('dir1/syslog.5', 'initially dir1/syslog.5');
1724 1724 set_file('dir1/syslog.6', 'initially dir1/syslog.6');
1725 1725 set_file('dir1/syslog.7', 'initially dir1/syslog.7');
1726 1726 mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
1727 1727 set_file('dir2/messages', 'initially dir2/messages');
1728 1728 set_file('dir2/messages.0', 'initially dir2/messages.0');
1729 1729 set_file('dir2/messages.1', 'initially dir2/messages.1');
1730 1730 set_file('dir2/messages.2', 'initially dir2/messages.2');
1731 1731 set_file('dir2/messages.3', 'initially dir2/messages.3');
1732 1732
1733 1733 set_file('logadm.conf', <<'EOF');
1734 1734 #
1735 1735 # logadm.conf
1736 1736 #
1737 1737 # Default settings for system log file management.
1738 1738 # The -w option to logadm(1M) is the preferred way to write to this file,
1739 1739 # but if you do edit it by hand, use "logadm -V" to check it for errors.
1740 1740 # but if you do edit it by hand, use "logadm -V" to check it for errors.
1741 1741 #
1742 1742 # The format of lines in this file is:
1743 1743 # <logname> <options>
1744 1744 # For each logname listed here, the default options to logadm
1745 1745 # are given. Options given on the logadm command line override
1746 1746 # the defaults contained in this file.
1747 1747 #
1748 1748 # logadm typically runs early every morning via an entry in
1749 1749 # root's crontab (see crontab(1)).
1750 1750 #
1751 1751 dir1/syslog -C 8 -a 'echo kill -HUP `cat /etc/syslog.pid` >> cmd.out'
1752 1752 dir2/messages -C 4 -a 'echo kill -HUP `cat /etc/syslog.pid` >> cmd.out'
1753 1753 #
1754 1754 # The entry below is used by turnacct(1M)
1755 1755 #
1756 1756 /var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
1757 1757 EOF
1758 1758
1759 1759 $gid = $);
1760 1760 $gid =~ s/ .*//;
1761 1761 set_file('grep.out.expect', <<'EOF'.<<"EOF".<<'EOF'.<<"EOF".<<'EOF');
1762 1762 # loading logadm.conf
1763 1763 # processing logname: dir1/syslog
1764 1764 # using default rotate rules: -s1b -p1w
1765 1765 # using default template: $file.$n
1766 1766 mkdir -p dir1 # verify directory exists
1767 1767 mv -f dir1/syslog.7 dir1/syslog.8 # rotate log file
1768 1768 mkdir -p dir1 # verify directory exists
1769 1769 mv -f dir1/syslog.6 dir1/syslog.7 # rotate log file
1770 1770 mkdir -p dir1 # verify directory exists
1771 1771 mv -f dir1/syslog.5 dir1/syslog.6 # rotate log file
1772 1772 mkdir -p dir1 # verify directory exists
1773 1773 mv -f dir1/syslog.4 dir1/syslog.5 # rotate log file
1774 1774 mkdir -p dir1 # verify directory exists
1775 1775 mv -f dir1/syslog.3 dir1/syslog.4 # rotate log file
1776 1776 mkdir -p dir1 # verify directory exists
1777 1777 mv -f dir1/syslog.2 dir1/syslog.3 # rotate log file
1778 1778 mkdir -p dir1 # verify directory exists
1779 1779 mv -f dir1/syslog.1 dir1/syslog.2 # rotate log file
1780 1780 mkdir -p dir1 # verify directory exists
1781 1781 mv -f dir1/syslog.0 dir1/syslog.1 # rotate log file
1782 1782 mkdir -p dir1 # verify directory exists
1783 1783 mv -f dir1/syslog dir1/syslog.0 # rotate log file
1784 1784 touch dir1/syslog
1785 1785 EOF
1786 1786 chown $>:$gid dir1/syslog
1787 1787 EOF
1788 1788 chmod 664 dir1/syslog
1789 1789 # processing logname: dir2/messages
1790 1790 # using default rotate rules: -s1b -p1w
1791 1791 # using default template: $file.$n
1792 1792 mkdir -p dir2 # verify directory exists
1793 1793 mv -f dir2/messages.3 dir2/messages.4 # rotate log file
1794 1794 mkdir -p dir2 # verify directory exists
1795 1795 mv -f dir2/messages.2 dir2/messages.3 # rotate log file
1796 1796 mkdir -p dir2 # verify directory exists
1797 1797 mv -f dir2/messages.1 dir2/messages.2 # rotate log file
1798 1798 mkdir -p dir2 # verify directory exists
1799 1799 mv -f dir2/messages.0 dir2/messages.1 # rotate log file
1800 1800 mkdir -p dir2 # verify directory exists
1801 1801 mv -f dir2/messages dir2/messages.0 # rotate log file
1802 1802 touch dir2/messages
1803 1803 EOF
1804 1804 chown $>:$gid dir2/messages
1805 1805 EOF
1806 1806 chmod 664 dir2/messages
1807 1807 # processing logname: /var/adm/pacct
1808 1808 # using default template: $file.$n
1809 1809 sh -c echo kill -HUP `cat /etc/syslog.pid` >> cmd.out # -a cmd
1810 1810 # logadm.conf and logadm.timestamps unchanged
1811 1811 EOF
1812 1812
1813 1813 set_file('checktest', <<'EOF');
1814 1814 [ -s std.err ] && { cat std.err; exit 1; }
1815 1815 [ -f std.out ] || exit 1
1816 1816 [ -f dir1/syslog ] || exit 1
1817 1817 [ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog`" ] || exit 1
1818 1818 [ -f dir1/syslog.0 ] || exit 1
1819 1819 [ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
1820 1820 [ -f dir1/syslog.1 ] || exit 1
1821 1821 [ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
1822 1822 [ -f dir1/syslog.2 ] || exit 1
1823 1823 [ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
1824 1824 [ -f dir1/syslog.3 ] || exit 1
1825 1825 [ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
1826 1826 [ -f dir1/syslog.4 ] || exit 1
1827 1827 [ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
1828 1828 [ -f dir1/syslog.5 ] || exit 1
1829 1829 [ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
1830 1830 [ -f dir1/syslog.6 ] || exit 1
1831 1831 [ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
1832 1832 [ -f dir1/syslog.7 ] || exit 1
1833 1833 [ "xinitially dir1/syslog.7" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
1834 1834 [ -f dir1/syslog.8 ] && exit 1
1835 1835
1836 1836 [ -f dir2/messages ] || exit 1
1837 1837 [ "xinitially dir2/messages" = "x`/bin/cat dir2/messages`" ] || exit 1
1838 1838 [ -f dir2/messages.0 ] || exit 1
1839 1839 [ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.0`" ] || exit 1
1840 1840 [ -f dir2/messages.1 ] || exit 1
1841 1841 [ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.1`" ] || exit 1
1842 1842 [ -f dir2/messages.2 ] || exit 1
1843 1843 [ "xinitially dir2/messages.2" = "x`/bin/cat dir2/messages.2`" ] || exit 1
1844 1844 [ -f dir2/messages.3 ] || exit 1
1845 1845 [ "xinitially dir2/messages.3" = "x`/bin/cat dir2/messages.3`" ] || exit 1
1846 1846 [ -f dir2/messages.4 ] && exit 1
1847 1847 /bin/grep -v 'recording rotation date' std.out > grep.out
1848 1848 exec /bin/diff grep.out.expect grep.out
1849 1849 EOF
1850 1850
1851 1851 set_file('runtest', <<"EOF");
1852 1852 # test "logadm14"
1853 1853 $envsetup
1854 1854 exec $bindir/logadm -nv -f logadm.conf -F logadm.timestamps >std.out 2>std.err
1855 1855 EOF
1856 1856 }
1857 1857
1858 1858 ###########################################################################
1859 1859 #
1860 1860 # logadm15 -- test of -T
1861 1861 #
1862 1862 ###########################################################################
1863 1863 sub logadm15 {
1864 1864 set_file('logfile', '');
1865 1865 set_file('logfile.0', 'initially logfile.0');
1866 1866 set_file('logfile.1', 'initially logfile.1');
1867 1867 set_file('logfile.2', 'initially logfile.2');
1868 1868 set_file('logfile.3', 'initially logfile.3');
1869 1869 set_file('logfile.4', 'initially logfile.4');
1870 1870 set_file('logfile.5', 'initially logfile.5');
1871 1871 set_file('logfile.6', 'initially logfile.6');
1872 1872 set_file('logfile.7', 'initially logfile.7');
1873 1873 set_file('logfile.8', 'initially logfile.8');
1874 1874 set_file('logfile.9', 'initially logfile.9');
1875 1875
1876 1876 set_file('checktest', <<'EOF');
1877 1877 [ -s std.err ] && { cat std.err; exit 1; }
1878 1878 [ -s std.out ] && exit 1
1879 1879 [ -f logfile ] || exit 1
1880 1880 [ "x" = "x`/bin/cat logfile`" ] || exit 1
1881 1881 [ -f logfile.0 ] || exit 1
1882 1882 [ "xinitially logfile.0" = "x`/bin/cat logfile.0`" ] || exit 1
1883 1883 [ -f logfile.1 ] || exit 1
1884 1884 [ "xinitially logfile.1" = "x`/bin/cat logfile.1`" ] || exit 1
1885 1885 [ -f logfile.2 ] || exit 1
1886 1886 [ "xinitially logfile.2" = "x`/bin/cat logfile.2`" ] || exit 1
1887 1887 [ -f logfile.3 ] && exit 1
1888 1888 [ -f logfile.4 ] || exit 1
1889 1889 [ "xinitially logfile.4" = "x`/bin/cat logfile.4`" ] || exit 1
1890 1890 [ -f logfile.5 ] && exit 1
1891 1891 [ -f logfile.6 ] || exit 1
1892 1892 [ "xinitially logfile.6" = "x`/bin/cat logfile.6`" ] || exit 1
1893 1893 [ -f logfile.7 ] && exit 1
1894 1894 [ -f logfile.8 ] || exit 1
1895 1895 [ "xinitially logfile.8" = "x`/bin/cat logfile.8`" ] || exit 1
1896 1896 [ -f logfile.9 ] && exit 1
1897 1897 [ -f logfile.10 ] && exit 1
1898 1898 exit 0
1899 1899 EOF
1900 1900
1901 1901 set_file('runtest', <<"EOF");
1902 1902 # test "logadm15"
1903 1903 $envsetup
1904 1904 exec $bindir/logadm -f /dev/null logfile -C1 -T '*.[13579]'>std.out 2>std.err
1905 1905 EOF
1906 1906 }
1907 1907
1908 1908 ###########################################################################
1909 1909 #
1910 1910 # logadm16 -- test of -h
1911 1911 #
1912 1912 ###########################################################################
1913 1913 sub logadm16 {
1914 1914 set_file('std.err.expect', <<'EOF');
1915 1915 Usage: logadm [options]
1916 1916 (processes all entries in /etc/logadm.conf or conffile given by -f)
1917 1917 or: logadm [options] logname...
1918 1918 (processes the given lognames)
1919 1919
1920 1920 General options:
1921 1921 -e mailaddr mail errors to given address
1922 1922 -F timestamps use timestamps instead of /var/logadm/timestamps
1923 1923 -f conffile use conffile instead of /etc/logadm.conf
1924 1924 -h display help
1925 1925 -N not an error if log file nonexistent
1926 1926 -n show actions, don't perform them
1927 1927 -r remove logname entry from conffile
1928 1928 -V ensure conffile entries exist, correct
1929 1929 -v print info about actions happening
1930 1930 -w entryname write entry to config file
1931 1931
1932 1932 Options which control when a logfile is rotated:
1933 1933 (default is: -s1b -p1w if no -s or -p)
1934 1934 -p period only rotate if period passed since last rotate
1935 1935 -P timestamp used to store rotation date in conffile
1936 1936 -s size only rotate if given size or greater
1937 1937
1938 1938 Options which control how a logfile is rotated:
1939 1939 (default is: -t '$file.$n', owner/group/mode taken from log file)
1940 1940 -a cmd execute cmd after taking actions
1941 1941 -b cmd execute cmd before taking actions
1942 1942 -c copy & truncate logfile, don't rename
1943 1943 -g group new empty log file group
1944 1944 -l rotate log file with local time rather than UTC
1945 1945 -m mode new empty log file mode
1946 1946 -M cmd execute cmd to rotate the log file
1947 1947 -o owner new empty log file owner
1948 1948 -R cmd run cmd on file after rotate
1949 1949 -t template template for naming old logs
1950 1950 -z count gzip old logs except most recent count
1951 1951
1952 1952 Options which control the expiration of old logfiles:
1953 1953 (default is: -C10 if no -A, -C, or -S)
1954 1954 -A age expire logs older than age
1955 1955 -C count expire old logs until count remain
1956 1956 -E cmd run cmd on file to expire
1957 1957 -S size expire until space used is below size
1958 1958 -T pattern pattern for finding old logs
1959 1959 EOF
1960 1960
1961 1961 set_file('checktest', <<'EOF');
1962 1962 [ -s std.out ] && exit 1
1963 1963 exec /bin/diff std.err.expect std.err
1964 1964 EOF
1965 1965
1966 1966 set_file('runtest', <<"EOF");
1967 1967 # test "logadm16"
1968 1968 $envsetup
1969 1969 exec $bindir/logadm -h >std.out 2>std.err
1970 1970 EOF
1971 1971 }
1972 1972
1973 1973 ###########################################################################
1974 1974 #
1975 1975 # logadm17 -- test that mkdir -p happens as necessary
1976 1976 #
1977 1977 ###########################################################################
1978 1978 sub logadm17 {
1979 1979 set_file('logfile', 'initially logfile');
1980 1980
1981 1981 set_file('checktest', <<'EOF');
1982 1982 [ -s std.err ] && { cat std.err; exit 1; }
1983 1983 [ -s std.out ] && exit 1
1984 1984 [ -f dir1/dir2/logfile ] || exit 1
1985 1985 [ -f logfile ] || exit 1
1986 1986 [ "xinitially logfile" = "x`/bin/cat dir1/dir2/logfile`" ] || exit 1
1987 1987 exit 0
1988 1988 EOF
1989 1989
1990 1990 set_file('runtest', <<"EOF");
1991 1991 # test "logadm17"
1992 1992 $envsetup
1993 1993 exec $bindir/logadm -f /dev/null -t 'dir1/dir2/\$basename' logfile -p now >std.out 2>std.err
1994 1994 EOF
1995 1995 }
1996 1996
1997 1997 ###########################################################################
1998 1998 #
1999 1999 # logadm18 -- test of -M option
2000 2000 #
2001 2001 ###########################################################################
2002 2002 sub logadm18 {
2003 2003 mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
2004 2004 set_file('dir1/syslog', 'initially dir1/syslog');
2005 2005 set_file('dir1/syslog.0', 'initially dir1/syslog.0');
2006 2006 set_file('dir1/syslog.1', 'initially dir1/syslog.1');
2007 2007 set_file('dir1/syslog.2', 'initially dir1/syslog.2');
2008 2008 set_file('dir1/syslog.3', 'initially dir1/syslog.3');
2009 2009 set_file('dir1/syslog.4', 'initially dir1/syslog.4');
2010 2010 set_file('dir1/syslog.5', 'initially dir1/syslog.5');
2011 2011 set_file('dir1/syslog.6', 'initially dir1/syslog.6');
2012 2012 set_file('dir1/syslog.7', 'initially dir1/syslog.7');
2013 2013
2014 2014 set_file('logadm.conf', <<"EOF");
2015 2015 dir1/syslog -C 8 -s 1b -M '/bin/tr [a-z] [A-Z] < \$file > \$nfile; /bin/rm -f \$file'
2016 2016 EOF
2017 2017
2018 2018 set_file('checktest', <<'EOF');
2019 2019 [ -s std.err ] && { cat std.err; exit 1; }
2020 2020 [ -s std.out ] && exit 1
2021 2021 [ -f dir1/syslog ] || exit 1
2022 2022 [ -s dir1/syslog ] && exit 1
2023 2023 [ -f dir1/syslog.0 ] || exit 1
2024 2024 [ "xINITIALLY DIR1/SYSLOG" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
2025 2025 [ -f dir1/syslog.1 ] || exit 1
2026 2026 [ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
2027 2027 [ -f dir1/syslog.2 ] || exit 1
2028 2028 [ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
2029 2029 [ -f dir1/syslog.3 ] || exit 1
2030 2030 [ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
2031 2031 [ -f dir1/syslog.4 ] || exit 1
2032 2032 [ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
2033 2033 [ -f dir1/syslog.5 ] || exit 1
2034 2034 [ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
2035 2035 [ -f dir1/syslog.6 ] || exit 1
2036 2036 [ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
2037 2037 [ -f dir1/syslog.7 ] || exit 1
2038 2038 [ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
2039 2039 [ -f dir1/syslog.8 ] && exit 1
2040 2040
2041 2041 exit 0
2042 2042 EOF
2043 2043
2044 2044 set_file('runtest', <<"EOF");
2045 2045 # test "logadm18"
2046 2046 $envsetup
2047 2047 exec $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err
2048 2048 EOF
2049 2049 }
2050 2050
2051 2051 #############################################################################
2052 2052 #
2053 2053 # logadm19 -- test of -l
2054 2054 #
2055 2055 #############################################################################
2056 2056 sub logadm19 {
2057 2057 set_file('logfile', 'initially logfile');
2058 2058
2059 2059 set_file('checktest', <<'EOF');
2060 2060 [ -s std.err ] && { cat std.err; exit 1; }
2061 2061 [ -s std.out ] && exit 1
2062 2062 [ -s logfile ] && exit 1
2063 2063 TZ= export TZ
2064 2064 d=`/bin/date +\%d\%H\%M`
2065 2065 [ -f logfile.$d ] || exit 1
2066 2066 [ "xinitially logfile" = "x`/bin/cat logfile.$d`" ] || exit 1
2067 2067 exit 0
2068 2068 EOF
2069 2069
2070 2070 set_file('runtest', <<"EOF");
2071 2071 # test "logadm19"
2072 2072 $envsetup
2073 2073 exec $bindir/logadm -f /dev/null -l -p now logfile -t '\$file.\%d\%H\%M' >std.out 2>std.err
2074 2074 EOF
2075 2075 }
2076 2076
2077 2077 #############################################################################
2078 2078 #
2079 2079 # logadm20 -- test of unquotables/error handling
2080 2080 #
2081 2081 #############################################################################
2082 2082 sub logadm20 {
2083 2083 set_file('logadm.conf', <<'EOF');
2084 2084 # non-trivial entry
2085 2085 /var/log/syslog -C 8 -a 'kill -HUP `cat /var/run/syslog.pid`'
2086 2086 EOF
2087 2087
2088 2088 set_file('std.err.expect', <<'EOF');
2089 2089 logadm: Error: Can't protect quotes in </bin/echo "She can't take anymore, Cap'n!">
2090 2090 logadm: Error: unsafe to update configuration file or timestamps
2091 2091 logadm: Error: bailing out due to command line errors
2092 2092 Use "logadm -h" for help.
2093 2093 exit=1
2094 2094 EOF
2095 2095
2096 2096 set_file('checktest', <<'EOF');
2097 2097 [ -s std.err ] || exit 1
2098 2098 [ -s std.out ] && exit 1
2099 2099 [ -f logadm.conf????? ] && exit 1
2100 2100 [ -f logadm.timestamps????? ] && exit 1
2101 2101 exec /bin/diff std.err.expect std.err
2102 2102 EOF
2103 2103
2104 2104 set_file('runtest', <<"EOF");
2105 2105 # test "logadm20"
2106 2106 $envsetup
2107 2107 $bindir/logadm -f logadm.conf -F logadm.timestamps -w /a/b/c -p 1w -l -b "/bin/echo \\"She can't take anymore, Cap'n!\\"" >std.out 2>std.err
2108 2108 echo exit=\$? >>std.err
2109 2109 EOF
2110 2110 }
↓ open down ↓ |
1269 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX