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