8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / logadm / tester
blobb65d13d155ec027c846348363420cc2ca6f47891
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"
96 use Getopt::Std;
97 use File::Find;
99 $usage_summary = '[-s test-name] [-d dir] bindir [test-name...]';
100 $usage_getopts = 'fd:s:';
101 %usage = (
102 d=>'use dir for tests rather than creating one in /tmp',
103 s=>'setup only, do not run test');
105 # spew usage message, plus any given message, and exit
106 sub usage {
107 my $msg = shift;
109 if ($msg) {
110 chomp $msg;
111 warn "$0: $msg\n" if $msg;
113 warn "Usage: $0 $usage_summary\n";
114 foreach (sort keys %usage) {
115 warn " -$_ $usage{$_}\n";
117 exit 1;
121 # basic argument processing
123 $myname = $0;
124 $myname =~ s/.*\///; # just show last component in error mesages
125 getopts($usage_getopts) or usage;
126 $bindir = shift or usage;
127 usage("$bindir does not exist") unless -d $bindir;
128 usage("cannot list more than one test with -s option") if $opt_s && @ARGV;
129 @tests = @ARGV if @ARGV;
130 print "Fast mode\n" if $opt_f;
131 $watchmalloc = 0 if $opt_f;
133 $mydir=`pwd`;
134 chomp $mydir;
136 $dir = $opt_d;
137 $dir = "/tmp/logadmtest$$" unless $dir = $opt_d;
139 if (!-d $dir) {
140 mkdir $dir, 0777 or die "$myname: mkdir $dir: $!\n";
141 $needrmdir = 1;
144 chdir $dir or die "$myname: $dir: $!\n";
146 # common commands in runtest by tests
147 if ($watchmalloc) {
148 $envsetup =
149 "HOME=$dir export HOME; " .
150 "LD_PRELOAD=watchmalloc.so.1 export LD_PRELOAD; " .
151 "MALLOC_DEBUG=RW export MALLOC_DEBUG";
152 } else {
153 $envsetup = "HOME=$dir export HOME; ";
156 $| = 1; # a.k.a. setbuf(stdout, NULL)
158 if ($opt_s) {
160 # just setup the test, explain how to use it, and exit
162 $testname = $opt_s;
163 eval "&$opt_s";
164 die "$myname: ERROR: $@" if $@;
165 print "$myname: $testname setup complete, to run, cd to:\n";
166 print " $dir\n";
167 print "and run the command:\n";
168 print " sh runtest\n";
169 print "to check the results, run the command:\n";
170 print " sh checktest\n";
171 exit 0;
172 } else {
174 # run all the tests
176 foreach (@tests) {
177 $testname = $_;
178 print "Running $testname...";
179 eval "&$_";
180 if ($@) {
181 print " SETUP FAILURE\n";
182 print STDERR "$myname: ERROR: $@";
183 exit 1;
185 eval "runner('runtest')";
186 if ($@) {
187 print " RUNTEST FAILURE\n";
188 print STDERR "$myname: ERROR: $@";
189 print STDERR "results captured in directory $dir\n";
190 print STDERR " or use: $myname -s $testname $bindir\n";
191 print STDERR " to do a fresh setup of this test.\n";
192 exit 1;
194 eval "runner('checktest', '-x', '> checktest.out 2>&1')";
195 if ($@) {
196 print " CHECKTEST FAILURE\n";
197 print STDERR "$myname: ERROR: $@";
198 print STDERR "results captured in file $dir/checktest.out\n";
199 print STDERR " or use: $myname -s $testname $bindir\n";
200 print STDERR " to do a fresh setup of this test.\n";
201 exit 1;
203 print "pass\n";
204 # sanity...
205 die "unexpected dir $dir" unless $dir =~ m,/.+/,;
206 system("/bin/rm -rf $dir/*");
210 # if we were the ones who created $dir, remove it
211 if ($needrmdir) {
212 chdir $mydir;
213 rmdir $dir || die "$myname: rmdir $dir: $!\n";
216 exit 0;
219 # run a shell script and check for failure
221 # the shell scripts generated by this program always "exec" the binary
222 # under test so checking here are for exit code, signals, and core dump
223 # is actually checking the program under test and not /bin/sh
225 sub runner {
226 my ($cmd, $prefix, $suffix) = (@_, '', '');
228 my $fullcmd = "/bin/sh $prefix $cmd $suffix";
229 my $rc = 0xffff & system("$fullcmd");
231 if ($rc == 0) {
232 return; # cmd completed normally
233 } elsif ($rc == 0xff00) {
234 die "command \"$cmd\" failed: $!\n";
235 } elsif (($rc & 0xff) == 0) {
236 $rc >>= 8;
237 die "command \"$cmd\" exit $rc\n";
238 } else {
239 my $coremsg;
240 $coremsg = " (core dumped)" if ($rc & 0x80);
241 $rc &= ~0x80;
242 die "command \"$cmd\" signal $rc$coremsg\n" ;
247 # set_file(filename [, contents]) -- create a file, optionally with contents
249 sub set_file {
250 my $file = shift;
251 my $contents = shift;
253 open SF, ">$file" or die "create \"$file\": $!\n";
254 print SF $contents if defined($contents);
255 close SF;
258 #############
259 #############
260 ############# THE TESTS START AFTER HERE...
261 #############
262 #############
264 # common setup step -- create a testfile.conf
265 sub set_testconffile {
266 my $fname = shift;
267 $fname = 'testfile.conf' unless defined($fname);
269 set_file($fname, <<'EOF');
271 # logadm.conf
273 # Default settings for system log file management.
274 # The -w option to logadm(1M) is the preferred way to write to this file,
275 # but if you do edit it by hand, use "logadm -V" to check it for errors.
277 # The format of lines in this file is:
278 # <logname> <options>
279 # For each logname listed here, the default options to logadm
280 # are given. Options given on the logadm command line override
281 # the defaults contained in this file.
283 # logadm typically runs early every morning via an entry in
284 # root's crontab (see crontab(1)).
286 /var/adm/messages -C 4 -P 'Thu Nov 1 16:56:42 2001' -a 'kill -HUP `cat /var/run/*syslog*pid`'
287 /var/cron/log -s 512k -t /var/cron/olog
288 /var/lp/logs/lpsched -C 2 -N -t '$file.$N'
290 # The entry below is used by turnacct(1M)
292 /var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
293 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'
294 /var/log/syslog -C 8 -P 'Thu Nov 1 09:16:38 2001' -a 'kill -HUP `cat /var/run/*syslog*pid`'
295 /var/apache/logs/access_log -P 'Thu Nov 1 08:27:56 2001'
296 /var/apache/logs/error_log -P 'Thu Nov 1 08:27:56 2001'
297 /var/apache/logs/suexec_log -P 'Thu Nov 1 08:27:56 2001'
298 /var/apache/logs/mod_jserv.log -P 'Thu Nov 1 08:27:56 2001'
299 /var/apache/logs/jserv.log -P 'Thu Nov 1 08:27:56 2001'
304 ###########################################################################
306 # conftest1 -- minimal basic test of the conf.c code
308 ###########################################################################
309 sub conftest1 {
310 set_testconffile;
312 set_file('checktest', <<'EOF');
313 [ -s std.err ] && { cat std.err; exit 1; }
314 /bin/sed '/^conffile <testfile.conf>:$/d' <std.out >sed.out
315 exec /bin/diff testfile.conf sed.out
318 set_file('runtest', <<"EOF");
319 # test "conftest1"
320 $envsetup
321 exec $bindir/conftest testfile.conf >std.out 2>std.err
325 ###########################################################################
327 # conftest2 -- error path through conf.c
329 ###########################################################################
330 sub conftest2 {
331 set_file('testfile.conf', 'line fragment');
333 set_file('std.err.expect', <<'EOF');
334 conftest: Warning: file testfile.conf doesn't end with newline, last line ignored.
337 set_file('checktest', <<'EOF');
338 exec /bin/diff std.err.expect std.err
341 set_file('runtest', <<"EOF");
342 # test "conftest2"
343 $envsetup
344 $bindir/conftest testfile.conf >std.out 2>std.err || exit 0
345 exit 1
349 ###########################################################################
351 # globtest1 -- minimal basic test of the glob.c code
353 ###########################################################################
354 sub globtest1 {
355 set_file('fileBname12');
356 sleep 2; # ensure above name is odler than below name
357 set_file('fileAname12');
358 set_file('fileAname1');
359 set_file('fileAname3');
360 set_file('fileAname5');
361 set_file('fileAname7');
362 set_file('fileAname9');
363 set_file('fileAname11');
364 set_file('fileBname0');
365 set_file('fileBname2');
366 set_file('fileBname4');
367 set_file('fileBname6');
368 set_file('fileBname8');
369 set_file('fileBname10');
370 mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
371 mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
372 mkdir 'dir3', 0777 or die "mkdir dir3: $!\n";
373 mkdir 'dir1/dirA', 0777 or die "mkdir dir1/dirA: $!\n";
374 mkdir 'dir1/dirB', 0777 or die "mkdir dir1/dirB: $!\n";
375 mkdir 'dir1/dirC', 0777 or die "mkdir dir1/dirC: $!\n";
376 mkdir 'dir2/dirA', 0777 or die "mkdir dir2/dirA: $!\n";
377 mkdir 'dir2/dirB', 0777 or die "mkdir dir2/dirB: $!\n";
378 mkdir 'dir2/dirC', 0777 or die "mkdir dir2/dirC: $!\n";
379 set_file('dir1/fileAname1');
380 set_file('dir1/fileAname2');
381 set_file('dir1/fileAname3');
382 set_file('dir1/fileAname4');
383 set_file('dir1/fileAname5');
384 set_file('dir1/fileBname1');
385 set_file('dir1/fileBname2');
386 set_file('dir1/fileBname3');
387 set_file('dir1/fileBname4');
388 set_file('dir1/fileBname5');
389 # supply some varying sizes to produce different total size values
390 set_file('dir1/dirA/fileAname4', '4444');
391 sleep 2; # ensure above file is oldest in dirA
392 set_file('dir1/dirA/fileAname1', '1');
393 set_file('dir1/dirA/fileAname2', '22');
394 set_file('dir1/dirA/fileAname3', '333');
395 set_file('dir1/dirA/fileAname5', '55555');
396 set_file('dir1/dirA/fileBname1', '1');
397 set_file('dir1/dirA/fileBname2', '22');
398 set_file('dir1/dirA/fileBname3', '333');
399 set_file('dir1/dirA/fileBname4', '4444');
400 set_file('dir1/dirA/fileBname5', '55555');
401 set_file('dir1/dirB/fileAname1', '1');
402 set_file('dir1/dirB/fileAname2', '22');
403 set_file('dir1/dirB/fileAname3', '333');
404 set_file('dir1/dirB/fileAname4', '4444');
405 set_file('dir1/dirB/fileAname5', '55555');
406 set_file('dir1/dirB/fileBname1', '1');
407 set_file('dir1/dirB/fileBname2', '22');
408 set_file('dir1/dirB/fileBname3', '333');
409 set_file('dir1/dirB/fileBname4', '4444');
410 set_file('dir1/dirB/fileBname5', '55555');
411 set_file('dir1/dirC/fileAname10', '12345678901');
412 set_file('dir1/dirC/fileAname20', '123456789022');
413 set_file('dir1/dirC/fileAname30', '1234567890333');
414 set_file('dir1/dirC/fileAname40', '12345678904444');
415 set_file('dir1/dirC/fileAname50', '123456789055555');
416 set_file('dir1/dirC/fileBname10', '12345678901');
417 set_file('dir1/dirC/fileBname20', '123456789022');
418 set_file('dir1/dirC/fileBname30', '1234567890333');
419 set_file('dir1/dirC/fileBname40', '12345678904444');
420 set_file('dir1/dirC/fileBname50', '123456789055555');
422 set_file('std.out.expect', <<'EOF');
423 <file{A,B,C}name*>:
424 <./fileAname12>
425 <./fileAname1>
426 <./fileAname3>
427 <./fileAname5>
428 <./fileAname7>
429 <./fileAname9>
430 <./fileAname11>
431 <./fileBname12>
432 <./fileBname0>
433 <./fileBname2>
434 <./fileBname4>
435 <./fileBname6>
436 <./fileBname8>
437 <./fileBname10>
438 total size: 0
439 oldest <./fileBname12>
440 oldest <./fileBname8>
441 oldest <./fileBname6>
442 oldest <./fileBname4>
443 oldest <./fileBname2>
444 oldest <./fileBname10>
445 oldest <./fileBname0>
446 oldest <./fileAname9>
447 oldest <./fileAname7>
448 oldest <./fileAname5>
449 oldest <./fileAname3>
450 oldest <./fileAname12>
451 oldest <./fileAname11>
452 oldest <./fileAname1>
453 <file{A,B,C}name>:
454 <fileAname>
455 <fileBname>
456 <fileCname>
457 total size: 0
458 oldest <fileCname>
459 oldest <fileBname>
460 oldest <fileAname>
461 <dir1/dirA/file*>:
462 <./dir1/dirA/fileAname4>
463 <./dir1/dirA/fileAname1>
464 <./dir1/dirA/fileAname2>
465 <./dir1/dirA/fileAname3>
466 <./dir1/dirA/fileAname5>
467 <./dir1/dirA/fileBname1>
468 <./dir1/dirA/fileBname2>
469 <./dir1/dirA/fileBname3>
470 <./dir1/dirA/fileBname4>
471 <./dir1/dirA/fileBname5>
472 total size: 30
473 oldest <./dir1/dirA/fileAname4>
474 oldest <./dir1/dirA/fileBname5>
475 oldest <./dir1/dirA/fileBname4>
476 oldest <./dir1/dirA/fileBname3>
477 oldest <./dir1/dirA/fileBname2>
478 oldest <./dir1/dirA/fileBname1>
479 oldest <./dir1/dirA/fileAname5>
480 oldest <./dir1/dirA/fileAname3>
481 oldest <./dir1/dirA/fileAname2>
482 oldest <./dir1/dirA/fileAname1>
483 <dir[13]/[e-z]*>:
484 <./dir1/fileAname1>
485 <./dir1/fileAname2>
486 <./dir1/fileAname3>
487 <./dir1/fileAname4>
488 <./dir1/fileAname5>
489 <./dir1/fileBname1>
490 <./dir1/fileBname2>
491 <./dir1/fileBname3>
492 <./dir1/fileBname4>
493 <./dir1/fileBname5>
494 total size: 0
495 oldest <./dir1/fileBname5>
496 oldest <./dir1/fileBname4>
497 oldest <./dir1/fileBname3>
498 oldest <./dir1/fileBname2>
499 oldest <./dir1/fileBname1>
500 oldest <./dir1/fileAname5>
501 oldest <./dir1/fileAname4>
502 oldest <./dir1/fileAname3>
503 oldest <./dir1/fileAname2>
504 oldest <./dir1/fileAname1>
505 <dir?/dir[AC]/fileBname[2-9]>:
506 <./dir1/dirA/fileBname2>
507 <./dir1/dirA/fileBname3>
508 <./dir1/dirA/fileBname4>
509 <./dir1/dirA/fileBname5>
510 total size: 14
511 oldest <./dir1/dirA/fileBname5>
512 oldest <./dir1/dirA/fileBname4>
513 oldest <./dir1/dirA/fileBname3>
514 oldest <./dir1/dirA/fileBname2>
515 <file[A-Z]n.*e([0-9]+)$0>:
516 <./fileBname12>
517 <./fileAname12>
518 <./fileAname1>
519 <./fileAname3>
520 <./fileAname5>
521 <./fileAname7>
522 <./fileAname9>
523 <./fileAname11>
524 <./fileBname0>
525 <./fileBname2>
526 <./fileBname4>
527 <./fileBname6>
528 <./fileBname8>
529 <./fileBname10>
530 total size: 0
531 oldest <./fileBname12>
532 oldest <./fileAname12>
533 oldest <./fileAname11>
534 oldest <./fileBname10>
535 oldest <./fileAname9>
536 oldest <./fileBname8>
537 oldest <./fileAname7>
538 oldest <./fileBname6>
539 oldest <./fileAname5>
540 oldest <./fileBname4>
541 oldest <./fileAname3>
542 oldest <./fileBname2>
543 oldest <./fileAname1>
544 oldest <./fileBname0>
547 set_file('checktest', <<'EOF');
548 [ -s std.err ] && { cat std.err; exit 1; }
549 exec /bin/diff std.out.expect std.out
552 $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\'';
554 set_file('runtest', <<"EOF");
555 # test "globtest1"
556 $envsetup
557 exec $bindir/globtest $testglobs >std.out 2>std.err
561 ###########################################################################
563 # globtest2 -- error path through glob.c
565 ###########################################################################
566 sub globtest2 {
567 set_file('std.err.expect', <<'EOF');
568 globtest: Error: Missing }
571 set_file('checktest', <<'EOF');
572 exec /bin/diff std.err.expect std.err
575 set_file('runtest', <<"EOF");
576 # test "globtest2"
577 $envsetup
578 $bindir/globtest 'hello{there' >std.out 2>std.err || exit 0
579 exit 1
583 ###########################################################################
585 # kwtest1 -- minimal basic test of the kw.c code
587 ###########################################################################
588 sub kwtest1 {
589 $domainname = `/bin/domainname`; chomp $domainname;
590 $isa = `/bin/uname -p`; chomp $isa;
591 $platform = `/bin/uname -i`; chomp $platform;
592 $nodename = `/bin/uname -n`; chomp $nodename;
593 $machine = `/bin/uname -m`; chomp $machine;
594 $release = `/bin/uname -r`; chomp $release;
595 # /bin/zonename is in SUNWzoneu and so may not be present
596 if (-f "/bin/zonename") {
597 $zonename = `/bin/zonename`; chomp $zonename;
598 } else {
599 $zonename = "global";
601 $secondblob=<<'EOF';
602 expand<$file.$n> n -1 hasn 1 result </var/log/syslog\.([0-9]+)$0>
603 expand<$file.$n> n 0 hasn 1 result </var/log/syslog.0>
604 expand<$file.$n> n 1 hasn 1 result </var/log/syslog.1>
605 expand<moose%d.$n> n -1 hasn 1 result <moose[0-9]+\.([0-9]+)$0>
606 expand<moose%d.$n> n 0 hasn 1 result <moose%d.0>
607 expand<moose%d.$n> n 1 hasn 1 result <moose%d.1>
608 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>
609 expand</var/logs-%Y/moose-$isa$#porklips%d.$n> n 0 hasn 1 result </var/logs-%Y/moose-ISAporklips%d.0>
610 expand</var/logs-%Y/moose-$isa$#porklips%d.$n> n 1 hasn 1 result </var/logs-%Y/moose-ISAporklips%d.1>
612 $percentd = `/bin/env TZ=UTC /bin/date +%d`; chomp $percentd;
613 $percentY = `/bin/env TZ=UTC /bin/date +%Y`; chomp $percentY;
614 $secondblob =~ s/%d/$percentd/mg;
615 $secondblob =~ s/%Y/$percentY/mg;
616 $secondblob =~ s/ISA/$isa/mg;
617 $utcenv = "TZ=UTC export TZ";
618 chomp $secondblob;
619 set_file('sed.out.expect', <<"EOF");
620 basename syslog
621 dirname /var/log
622 domain $domainname
623 file /var/log/syslog
624 home $dir
625 isa $isa
626 logname $ENV{LOGNAME}
627 machine $machine
628 nfile
629 nodename $nodename
630 platform $platform
631 release $release
632 user $ENV{USER}
633 zonename $zonename
634 $secondblob
637 set_file('checktest', <<'EOF');
638 [ -s std.err ] && { cat std.err; exit 1; }
639 /bin/sed -e '/^ *secs [0-9][0-9]*$/d'\
640 -e "s/%d/`/bin/env TZ=UTC /bin/date +%d`/g"\
641 -e "s/%Y/`/bin/env TZ=UTC /bin/date +%Y`/g"\
642 <std.out >sed.out
643 exec /bin/diff sed.out.expect sed.out
646 $kwtest='kwtest /var/log/syslog \'$file.$n\' \'moose%d.$n\' \'/var/logs-%Y/moose-$isa$#porklips%d.$n\'';
647 set_file('runtest', <<"EOF");
648 # test "kwtest1"
649 $envsetup
650 $utcenv
651 exec $bindir/$kwtest >std.out 2>std.err
655 ###########################################################################
657 # kwtest2 -- NULL environment variables test of the kw.c code
659 ###########################################################################
660 sub kwtest2 {
661 $domainname = `/bin/domainname`; chomp $domainname;
662 $isa = `/bin/uname -p`; chomp $isa;
663 $platform = `/bin/uname -i`; chomp $platform;
664 $nodename = `/bin/uname -n`; chomp $nodename;
665 $machine = `/bin/uname -m`; chomp $machine;
666 $release = `/bin/uname -r`; chomp $release;
667 # /bin/zonename is in SUNWzoneu and so may not be present
668 if (-f "/bin/zonename") {
669 $zonename = `/bin/zonename`; chomp $zonename;
670 } else {
671 $zonename = "global";
673 $secondblob=<<'EOF';
674 expand<$file.$n> n -1 hasn 1 result </var/log/syslog\.([0-9]+)$0>
675 expand<$file.$n> n 0 hasn 1 result </var/log/syslog.0>
676 expand<$file.$n> n 1 hasn 1 result </var/log/syslog.1>
677 expand<moose%d.$n> n -1 hasn 1 result <moose[0-9]+\.([0-9]+)$0>
678 expand<moose%d.$n> n 0 hasn 1 result <moose%d.0>
679 expand<moose%d.$n> n 1 hasn 1 result <moose%d.1>
680 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>
681 expand</var/logs-%Y/moose-$isa$#porklips%d.$n> n 0 hasn 1 result </var/logs-%Y/moose-ISAporklips%d.0>
682 expand</var/logs-%Y/moose-$isa$#porklips%d.$n> n 1 hasn 1 result </var/logs-%Y/moose-ISAporklips%d.1>
684 $percentd = `/bin/env TZ=UTC /bin/date +%d`; chomp $percentd;
685 $percentY = `/bin/env TZ=UTC /bin/date +%Y`; chomp $percentY;
686 $secondblob =~ s/%d/$percentd/mg;
687 $secondblob =~ s/%Y/$percentY/mg;
688 $secondblob =~ s/ISA/$isa/mg;
689 chomp $secondblob;
690 set_file('sed.out.expect', <<"EOF");
691 basename syslog
692 dirname /var/log
693 domain $domainname
694 file /var/log/syslog
695 home
696 isa $isa
697 logname
698 machine $machine
699 nfile
700 nodename $nodename
701 platform $platform
702 release $release
703 user
704 zonename $zonename
705 $secondblob
708 set_file('checktest', <<'EOF');
709 [ -s std.err ] && { cat std.err; exit 1; }
710 /bin/sed -e '/^ *secs [0-9][0-9]*$/d'\
711 -e "s/%d/`/bin/env TZ=UTC /bin/date +%d`/g"\
712 -e "s/%Y/`/bin/env TZ=UTC /bin/date +%Y`/g"\
713 <std.out >sed.out
714 exec /bin/diff sed.out.expect sed.out
717 $kwtest='kwtest /var/log/syslog \'$file.$n\' \'moose%d.$n\' \'/var/logs-%Y/moose-$isa$#porklips%d.$n\'';
718 set_file('runtest', <<"EOF");
719 # test "kwtest2"
720 $envsetup
721 LOGNAME=
722 export LOGNAME
723 HOME=
724 export HOME
725 USER=
726 export USER
727 TZ=UTC
728 export TZ
729 exec $bindir/$kwtest >std.out 2>std.err
733 ###########################################################################
735 # luttest1 -- minimal basic test of the lut.c code
737 ###########################################################################
738 sub luttest1 {
739 set_file('std.out.expect', <<'EOF');
740 lut contains:
741 <fix> <NULL> (<NULL>)
742 <one> <two> (<two>)
743 <seven> <eight> (<eight>)
744 <six> <NULL> (<NULL>)
745 <three> <four> (<four>)
746 dup lut contains:
747 <fix> <NULL> (<NULL>)
748 <one> <two> (<two>)
749 <seven> <eight> (<eight>)
750 <six> <NULL> (<NULL>)
751 <three> <four> (<four>)
754 set_file('checktest', <<'EOF');
755 [ -s std.err ] && { cat std.err; exit 1; }
756 exec /bin/diff std.out.expect std.out
759 set_file('runtest', <<"EOF");
760 # test "luttest1"
761 $envsetup
762 exec $bindir/luttest one=two three=four fix six seven=eight >std.out 2>std.err
766 ###########################################################################
768 # optstest1 -- minimal basic test of the opts.c code
770 ###########################################################################
771 sub optstest1 {
772 $options="-a -b moose -c 1h -d 'Fri Nov 2 13:19:55 2001' -e 1k -f 2 one two three";
773 set_file('std.out.expect', <<"EOF");
774 options: $options
777 set_file('checktest', <<'EOF');
778 [ -s std.err ] && { cat std.err; exit 1; }
779 exec /bin/diff std.out.expect std.out
782 set_file('runtest', <<"EOF");
783 # test "optstest1"
784 $envsetup
785 exec $bindir/optstest $options >std.out 2>std.err
789 ###########################################################################
791 # optstest2 -- error path through opts.c code
793 ###########################################################################
794 sub optstest2 {
795 $options="-a -b -c 1h -d 'Fri Nov 2 13:19:55 2001' -e 1k -f 2 one two three";
796 set_file('std.err.expect', <<'EOF');
797 optstest: Error: Option 'b' requires an argument
798 optstest: Error: opts parsing failed
801 set_file('checktest', <<'EOF');
802 [ -s std.out ] && exit 1
803 exec /bin/diff std.err.expect std.err
806 set_file('runtest', <<"EOF");
807 # test "optstest2"
808 $envsetup
809 $bindir/optstest $options >std.out 2>std.err || exit 0
810 exit 1
814 ###########################################################################
816 # logadmV1 -- test of "logadm -V"
818 ###########################################################################
819 sub logadmV1 {
820 set_testconffile;
822 set_file('std.out.expect', <<'EOF');
823 /var/adm/messages -C 4 -P 'Thu Nov 1 16:56:42 2001' -a 'kill -HUP `cat /var/run/*syslog*pid`'
824 /var/cron/log -s 512k -t /var/cron/olog
825 /var/lp/logs/lpsched -C 2 -N -t '$file.$N'
826 /var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
827 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'
828 /var/log/syslog -C 8 -P 'Thu Nov 1 09:16:38 2001' -a 'kill -HUP `cat /var/run/*syslog*pid`'
829 /var/apache/logs/access_log -P 'Thu Nov 1 08:27:56 2001'
830 /var/apache/logs/error_log -P 'Thu Nov 1 08:27:56 2001'
831 /var/apache/logs/suexec_log -P 'Thu Nov 1 08:27:56 2001'
832 /var/apache/logs/mod_jserv.log -P 'Thu Nov 1 08:27:56 2001'
833 /var/apache/logs/jserv.log -P 'Thu Nov 1 08:27:56 2001'
836 set_file('checktest', <<'EOF');
837 [ -s std.err ] && { cat std.err; exit 1; }
838 exec /bin/diff std.out.expect std.out
841 set_file('runtest', <<"EOF");
842 # test "logadmV1"
843 $envsetup
844 exec $bindir/logadm -f testfile.conf -F testfile.conf -V >std.out 2>std.err
848 ###########################################################################
850 # logadmV2 -- test of "logadm -V <entry>"
852 ###########################################################################
853 sub logadmV2 {
854 set_testconffile;
856 set_file('std.out.expect', <<'EOF');
857 /var/cron/log -s 512k -t /var/cron/olog
858 /var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
861 set_file('checktest', <<'EOF');
862 [ -s std.err ] && { cat std.err; exit 1; }
863 exec /bin/diff std.out.expect std.out
866 set_file('runtest', <<"EOF");
867 # test "logadmV2"
868 $envsetup
869 exec $bindir/logadm -f testfile.conf -F testfile.conf -V /var/cron/log /var/adm/pacct >std.out 2>std.err
873 ###########################################################################
875 # logadmr -- test of "logadm -r <entry>"
877 ###########################################################################
878 sub logadmr {
879 set_testconffile;
880 set_testconffile('testfile.conf.orig');
882 set_file('diff.out.expect', <<'EOF');
883 18d17
884 < /var/cron/log -s 512k -t /var/cron/olog
885 23d21
886 < /var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
889 set_file('checktest', <<'EOF');
890 [ -s std.err ] && { cat std.err; exit 1; }
891 /bin/diff testfile.conf.orig testfile.conf > diff.out
892 exec /bin/diff diff.out.expect diff.out
895 set_file('runtest', <<"EOF");
896 # test "logadmr"
897 $envsetup
898 exec $bindir/logadm -f testfile.conf -F testfile.conf -r /var/cron/log /var/adm/pacct >std.out 2>std.err
902 ###########################################################################
904 # logadmw -- test of "logadm -w <entry>"
906 ###########################################################################
907 sub logadmw {
908 set_testconffile;
909 set_testconffile('testfile.conf.orig');
911 set_file('diff.out.expect', <<'EOF');
912 30a31
913 > moose -C 20 -a moose_after_cmd -g pig -m 664 -o cow -p never /moose/file
916 set_file('checktest', <<'EOF');
917 [ -s std.err ] && { cat std.err; exit 1; }
918 /bin/diff testfile.conf.orig testfile.conf > diff.out
919 exec /bin/diff diff.out.expect diff.out
922 set_file('runtest', <<"EOF");
923 # test "logadmw"
924 $envsetup
925 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
929 ###########################################################################
931 # logadm1 -- minimal basic test of logadm rotation
933 ###########################################################################
934 sub logadm1 {
935 set_file('logfile', 'initially logfile');
936 set_file('logfile.0', 'initially logfile.0');
937 my ($stdev, $stino, $stmode, $stnlink, $stuid, $stgid, $strdev,
938 $stsize, $statime, $stmtime, $stctime, $stblksize, $stblocks) =
939 lstat 'logfile' or die "lstat logfile: $!\n";
941 set_file('checktest', <<"EOF");
942 [ -s std.err ] && { cat std.err; exit 1; }
943 [ -s std.out ] && exit 1
944 [ -s logfile ] && exit 1
945 [ -f logfile.0 ] || exit 1
946 [ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
947 [ "`/bin/ls -i logfile.0 | /bin/awk '{ print \$1; }'`" = "$stino" ] || exit 1
948 [ -f logfile.1 ] || exit 1
949 [ "xinitially logfile.0" = "x`/bin/cat logfile.1`" ] || exit 1
950 exit 0
953 set_file('runtest', <<"EOF");
954 # test "logadm1"
955 $envsetup
956 exec $bindir/logadm -f /dev/null -p now logfile >std.out 2>std.err
960 ###########################################################################
962 # logadm1c -- same as logadm1 but with -c option
964 ###########################################################################
965 sub logadm1c {
966 set_file('logfile', 'initially logfile');
967 set_file('logfile.0', 'initially logfile.0');
968 my ($stdev, $stino, $stmode, $stnlink, $stuid, $stgid, $strdev,
969 $stsize, $statime, $stmtime, $stctime, $stblksize, $stblocks) =
970 lstat 'logfile' or die "lstat logfile: $!\n";
972 set_file('checktest', <<"EOF");
973 [ -s std.err ] && { cat std.err; exit 1; }
974 [ -s std.out ] && exit 1
975 [ -s logfile ] && exit 1
976 [ -f logfile.0 ] || exit 1
977 [ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
978 [ "`/bin/ls -i logfile.0 | /bin/awk '{ print \$1; }'`" = "$stino" ] && exit 1
979 [ -f logfile.1 ] || exit 1
980 [ "xinitially logfile.0" = "x`/bin/cat logfile.1`" ] || exit 1
981 exit 0
984 set_file('runtest', <<"EOF");
985 # test "logadm1c"
986 $envsetup
987 exec $bindir/logadm -f /dev/null -p now -c logfile >std.out 2>std.err
991 ###########################################################################
993 # logadm2 -- minimal basic test of logadm expiration
995 ###########################################################################
996 sub logadm2 {
997 set_file('logfile', 'initially logfile');
998 set_file('logfile.0', 'initially logfile.0');
999 set_file('logfile.1', 'initially logfile.1');
1001 set_file('checktest', <<'EOF');
1002 [ -s std.err ] && { cat std.err; exit 1; }
1003 [ -s std.out ] && exit 1
1004 [ -s logfile ] && exit 1
1005 [ -f logfile.0 ] || exit 1
1006 [ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
1007 [ -f logfile.1 ] || exit 1
1008 [ "xinitially logfile.0" = "x`/bin/cat logfile.1`" ] || exit 1
1009 [ -f logfile.2 ] && exit 1
1010 exit 0
1013 set_file('runtest', <<"EOF");
1014 # test "logadm2"
1015 $envsetup
1016 exec $bindir/logadm -f /dev/null -p now logfile -C2 >std.out 2>std.err
1020 ###########################################################################
1022 # logadm3 -- minimal basic test of logadm pre/post-commands
1024 ###########################################################################
1025 sub logadm3 {
1026 set_file('logfile', 'initially logfile');
1027 set_file('logfile.0', 'initially logfile.0');
1028 set_file('logfile.1', 'initially logfile.1');
1030 set_file('checktest', <<'EOF');
1031 [ -s std.err ] && { cat std.err; exit 1; }
1032 [ -s std.out ] && exit 1
1033 [ -s logfile ] && exit 1
1034 [ -f logfile.0 ] || exit 1
1035 [ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
1036 [ -f logfile.1 ] || exit 1
1037 [ "xinitially logfile.0" = "x`/bin/cat logfile.1`" ] || exit 1
1038 [ -f logfile.2 ] && exit 1
1039 [ -f pre.out ] || exit 1
1040 [ "xpre-command-stuff" = "x`/bin/cat pre.out`" ] || exit 1
1041 [ -f post.out ] || exit 1
1042 [ "xpost-command-stuff" = "x`/bin/cat post.out`" ] || exit 1
1043 exit 0
1046 set_file('runtest', <<"EOF");
1047 # test "logadm3"
1048 $envsetup
1049 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
1053 ###########################################################################
1055 # logadm4 -- test of -t template
1057 ###########################################################################
1058 sub logadm4 {
1059 set_file('logfile', 'initially logfile');
1061 set_file('checktest', <<'EOF');
1062 [ -s std.err ] && { cat std.err; exit 1; }
1063 [ -s std.out ] && exit 1
1064 [ -s logfile ] && exit 1
1065 TZ=UTC export TZ
1066 d=`/bin/date +%d`
1067 [ -f logfile.$d ] || exit 1
1068 [ "xinitially logfile" = "x`/bin/cat logfile.$d`" ] || exit 1
1069 exit 0
1072 set_file('runtest', <<"EOF");
1073 # test "logadm4"
1074 $envsetup
1075 exec $bindir/logadm -f /dev/null -p now logfile -t '\$file.\%d' >std.out 2>std.err
1079 ###########################################################################
1081 # logadm5 -- test of -R cmd and -E cmd
1083 ###########################################################################
1084 sub logadm5 {
1085 set_file('logfile', 'initially logfile');
1086 set_file('logfile.0', 'initially logfile.0');
1088 set_file('cmd.out.expect', <<'EOF');
1089 just rotated: initially logfile
1090 just expired: initially logfile.0
1093 set_file('checktest', <<'EOF');
1094 [ -s std.err ] && { cat std.err; exit 1; }
1095 [ -s std.out ] && exit 1
1096 [ -s logfile ] && exit 1
1097 [ -f logfile.0 ] || exit 1
1098 [ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
1099 [ -f logfile.1 ] || exit 1
1100 [ "xinitially logfile.0" = "x`/bin/cat logfile.1`" ] || exit 1
1101 exec /bin/diff cmd.out.expect cmd.out
1104 set_file('runtest', <<"EOF");
1105 # test "logadm5"
1106 $envsetup
1107 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
1111 ###########################################################################
1113 # logadm6 -- test of -m, -o, -g
1115 ###########################################################################
1116 sub logadm6 {
1117 set_file('logfile', 'initially logfile');
1119 set_file('std.err.expect', <<'EOF');
1120 logadm: Warning: command failed: /bin/chown _nonexistentuser_:_nonexistentgroup_ logfile
1121 chown: unknown group id _nonexistentgroup_
1124 set_file('checktest', <<'EOF');
1125 [ -s std.err ] || exit 1;
1126 [ -s std.out ] && exit 1
1127 [ -s logfile ] && exit 1
1128 [ -f logfile.0 ] || exit 1
1129 [ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
1130 [ "`/bin/ls -l logfile | /bin/awk '{ print $1; }'`" = "-r----x--x" ] || exit 1
1131 exec /bin/diff std.err.expect std.err
1134 set_file('runtest', <<"EOF");
1135 # test "logadm6"
1136 $envsetup
1137 exec $bindir/logadm -f /dev/null -p now logfile -m 411 -o _nonexistentuser_ -g _nonexistentgroup_ >std.out 2>std.err
1141 ###########################################################################
1143 # logadm7 -- test running through a conffile
1145 ###########################################################################
1146 sub logadm7 {
1147 mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
1148 set_file('dir1/syslog', 'initially dir1/syslog');
1149 set_file('dir1/syslog.0', 'initially dir1/syslog.0');
1150 set_file('dir1/syslog.1', 'initially dir1/syslog.1');
1151 set_file('dir1/syslog.2', 'initially dir1/syslog.2');
1152 set_file('dir1/syslog.3', 'initially dir1/syslog.3');
1153 set_file('dir1/syslog.4', 'initially dir1/syslog.4');
1154 set_file('dir1/syslog.5', 'initially dir1/syslog.5');
1155 set_file('dir1/syslog.6', 'initially dir1/syslog.6');
1156 set_file('dir1/syslog.7', 'initially dir1/syslog.7');
1157 mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
1158 set_file('dir2/messages', 'initially dir2/messages');
1159 set_file('dir2/messages.0', 'initially dir2/messages.0');
1160 set_file('dir2/messages.1', 'initially dir2/messages.1');
1161 set_file('dir2/messages.2', 'initially dir2/messages.2');
1162 set_file('dir2/messages.3', 'initially dir2/messages.3');
1164 set_file('logadm.conf', <<'EOF');
1166 # logadm.conf
1168 # this comment # has at least another #-sign in it #...
1170 # Default settings for system log file management.
1171 # The -w option to logadm(1M) is the preferred way to write to this file,
1172 # but if you do edit it by hand, use "logadm -V" to check it for errors.
1173 # but if you do edit it by hand, use "logadm -V" to check it for errors.
1175 # The format of lines in this file is:
1176 # <logname> <options>
1177 # For each logname listed here, the default options to logadm
1178 # are given. Options given on the logadm command line override
1179 # the defaults contained in this file.
1181 # logadm typically runs early every morning via an entry in
1182 # root's crontab (see crontab(1)).
1184 dir1/syslog -C 8 -a 'echo kill -HUP `cat /var/run/*syslog*pid` >> cmd.out'
1185 dir2/messages -C 4 -a 'echo kill -HUP `cat /var/run/*syslog*pid` >> cmd.out'
1187 # The entry below is used by turnacct(1M)
1189 /var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
1192 system("/bin/cp logadm.conf logadm.conf.orig");
1194 $pid=`cat /var/run/*syslog*pid`;
1195 chomp $pid;
1196 set_file('cmd.out.expect', <<"EOF");
1197 kill -HUP $pid
1198 second kill -HUP $pid
1201 set_file('sed.out.expect', <<'EOF');
1202 # This file holds internal data for logadm(1M).
1203 # Do not edit.
1204 dir1/syslog
1205 dir2/messages
1208 set_file('checktest', <<'EOF');
1209 [ -s std.err ] && { cat std.err; exit 1; }
1210 [ -s std.out ] && exit 1
1211 [ -s logadm.timestamps ] || exit 1
1212 [ -s std.err2 ] && exit 1
1213 [ -s std.out2 ] && exit 1
1214 [ -s std.err3 ] && exit 1
1215 [ -s std.out3 ] && exit 1
1216 [ -s std.err4 ] && exit 1
1217 [ -s std.out4 ] && exit 1
1218 [ -f dir1/syslog ] || exit 1
1219 [ "xsomething" = "x`/bin/cat dir1/syslog`" ] || exit 1
1220 [ -f dir1/syslog.0 ] || exit 1
1221 [ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
1222 [ -f dir1/syslog.1 ] || exit 1
1223 [ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
1224 [ -f dir1/syslog.2 ] || exit 1
1225 [ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
1226 [ -f dir1/syslog.3 ] || exit 1
1227 [ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
1228 [ -f dir1/syslog.4 ] || exit 1
1229 [ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
1230 [ -f dir1/syslog.5 ] || exit 1
1231 [ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
1232 [ -f dir1/syslog.6 ] || exit 1
1233 [ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
1234 [ -f dir1/syslog.7 ] || exit 1
1235 [ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
1236 [ -f dir1/syslog.8 ] && exit 1
1238 [ -s dir2/messages ] && exit 1
1239 [ -f dir2/messages.0 ] || exit 1
1240 [ "xsomething" = "x`/bin/cat dir2/messages.0`" ] || exit 1
1241 [ -f dir2/messages.1 ] || exit 1
1242 [ "xinitially dir2/messages" = "x`/bin/cat dir2/messages.1`" ] || exit 1
1243 [ -f dir2/messages.2 ] || exit 1
1244 [ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.2`" ] || exit 1
1245 [ -f dir2/messages.3 ] || exit 1
1246 [ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.3`" ] || exit 1
1247 [ -f dir2/messages.4 ] && exit 1
1248 /bin/sed "s/ -P '[^']*' *//" < logadm.timestamps > sed.out
1249 /bin/diff sed.out.expect sed.out || exit 1
1250 exec /bin/diff logadm.conf.orig logadm.conf
1253 # first logadm call will rotate both syslog and messages
1254 # second one won't because size is zero
1255 # third one won't because of -P timestamps stored in conffile
1256 # fourth one will do messages because of -p now on command line
1257 set_file('runtest', <<"EOF");
1258 # test "logadm7"
1259 $envsetup
1260 $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err || exit 1
1261 $bindir/logadm -f logadm.conf -F logadm.timestamps dir1/syslog dir2/messages >std.out2 2>std.err2 || exit 1
1262 echo something > dir1/syslog
1263 echo something > dir2/messages
1264 $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out3 2>std.err3 || exit 1
1265 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
1269 ###########################################################################
1271 # logadm8 -- test of -z
1273 ###########################################################################
1274 sub logadm8 {
1275 mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
1276 set_file('dir1/syslog', 'initially dir1/syslog');
1277 set_file('dir1/syslog.0', 'initially dir1/syslog.0');
1278 set_file('dir1/syslog.1', 'initially dir1/syslog.1');
1279 set_file('dir1/syslog.2', 'initially dir1/syslog.2');
1280 system("/bin/gzip dir1/syslog.2");
1281 die "gzip dir1/syslog.2 didn't work\n" unless -f 'dir1/syslog.2.gz';
1282 set_file('dir1/syslog.3', 'initially dir1/syslog.3');
1283 system("/bin/gzip dir1/syslog.3");
1284 die "gzip dir1/syslog.3 didn't work\n" unless -f 'dir1/syslog.3.gz';
1285 set_file('dir1/syslog.4', 'initially dir1/syslog.4');
1286 system("/bin/gzip dir1/syslog.4");
1287 die "gzip dir1/syslog.4 didn't work\n" unless -f 'dir1/syslog.4.gz';
1288 set_file('dir1/syslog.5', 'initially dir1/syslog.5');
1289 system("/bin/gzip dir1/syslog.5");
1290 die "gzip dir1/syslog.5 didn't work\n" unless -f 'dir1/syslog.5.gz';
1291 set_file('dir1/syslog.6', 'initially dir1/syslog.6');
1292 system("/bin/gzip dir1/syslog.6");
1293 die "gzip dir1/syslog.6 didn't work\n" unless -f 'dir1/syslog.6.gz';
1294 set_file('dir1/syslog.7', 'initially dir1/syslog.7');
1295 system("/bin/gzip dir1/syslog.7");
1296 die "gzip dir1/syslog.7 didn't work\n" unless -f 'dir1/syslog.7.gz';
1298 set_file('checktest', <<'EOF');
1299 [ -s std.err ] && { cat std.err; exit 1; }
1300 [ -s std.out ] && exit 1
1301 [ -f dir1/syslog ] || exit 1
1302 [ -s dir1/syslog ] && exit 1
1303 [ -f dir1/syslog.0 ] || exit 1
1304 [ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
1305 [ -f dir1/syslog.1 ] || exit 1
1306 [ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
1307 [ -f dir1/syslog.2.gz ] || exit 1
1308 [ "xinitially dir1/syslog.1" = "x`/bin/gzcat dir1/syslog.2.gz`" ] || exit 1
1309 [ -f dir1/syslog.3.gz ] || exit 1
1310 [ "xinitially dir1/syslog.2" = "x`/bin/gzcat dir1/syslog.3.gz`" ] || exit 1
1311 [ -f dir1/syslog.4.gz ] || exit 1
1312 [ "xinitially dir1/syslog.3" = "x`/bin/gzcat dir1/syslog.4.gz`" ] || exit 1
1313 [ -f dir1/syslog.5.gz ] || exit 1
1314 [ "xinitially dir1/syslog.4" = "x`/bin/gzcat dir1/syslog.5.gz`" ] || exit 1
1315 [ -f dir1/syslog.6.gz ] || exit 1
1316 [ "xinitially dir1/syslog.5" = "x`/bin/gzcat dir1/syslog.6.gz`" ] || exit 1
1317 [ -f dir1/syslog.7.gz ] || exit 1
1318 [ "xinitially dir1/syslog.6" = "x`/bin/gzcat dir1/syslog.7.gz`" ] || exit 1
1319 [ -f dir1/syslog.8 ] && exit 1
1320 [ -f dir1/syslog.8.gz ] && exit 1
1321 exit 0
1324 set_file('runtest', <<"EOF");
1325 # test "logadm8"
1326 $envsetup
1327 exec $bindir/logadm -f /dev/null dir1/syslog -z 2 -C 8 >std.out 2>std.err
1331 ###########################################################################
1333 # logadm9 -- test of age check
1335 ###########################################################################
1336 sub logadm9 {
1337 mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
1338 set_file('dir1/syslog', 'initially dir1/syslog');
1339 set_file('dir1/syslog.0', 'initially dir1/syslog.0');
1340 set_file('dir1/syslog.1', 'initially dir1/syslog.1');
1341 set_file('dir1/syslog.2', 'initially dir1/syslog.2');
1342 set_file('dir1/syslog.3', 'initially dir1/syslog.3');
1343 set_file('dir1/syslog.4', 'initially dir1/syslog.4');
1344 set_file('dir1/syslog.5', 'initially dir1/syslog.5');
1345 set_file('dir1/syslog.6', 'initially dir1/syslog.6');
1346 set_file('dir1/syslog.7', 'initially dir1/syslog.7');
1347 set_file('dir1/notes', 'initially dir1/notes');
1348 mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
1349 set_file('dir2/messages', 'initially dir2/messages');
1350 set_file('dir2/messages.0', 'initially dir2/messages.0');
1351 set_file('dir2/messages.1', 'initially dir2/messages.1');
1352 set_file('dir2/messages.2', 'initially dir2/messages.2');
1353 set_file('dir2/messages.3', 'initially dir2/messages.3');
1354 set_file('dir2/log', 'initially dir2/log');
1356 $now = time;
1357 $nowstr = gmtime($now);
1358 # a week minus 30 seconds ago...
1359 # technically not a full week, but the heuristic used by logadm
1360 # should think this is "close enough" to a full week
1361 $closetoweeksecs = $now - (60 * 60 * 24 * 7 - 30);
1362 $closetoweek = gmtime($closetoweeksecs);
1363 # a week minus six hours ago...
1364 $lessthanweeksecs = $now - (60 * 60 * 24 * 7 - 60 * 60 * 6);
1365 $lessthanweek = gmtime($lessthanweeksecs);
1367 set_file('logadm.conf', <<"EOF");
1368 # now: $nowstr is $now
1369 # $closetoweek is $closetoweeksecs
1370 dir1/syslog -C 8 -P '$closetoweek'
1371 dir2/log -C 4
1372 # $lessthanweek is $lessthanweeksecs
1373 dir1/notes -C 2 -P '$lessthanweek'
1374 dir2/messages -C 4
1376 set_file('logadm.timestamps', <<"EOF");
1377 dir2/log -P '$closetoweek'
1378 dir2/messages -P '$lessthanweek'
1381 set_file('sed.out.expect', <<"EOF");
1382 # This file holds internal data for logadm(1M).
1383 # Do not edit.
1384 dir1/syslog
1385 dir2/log
1386 dir1/notes
1387 dir2/messages
1390 set_file('checktest', <<'EOF');
1391 [ -s std.err ] && { cat std.err; exit 1; }
1392 [ -s std.out ] && exit 1
1393 [ -f dir1/syslog ] || exit 1
1394 [ -s dir1/syslog ] && exit 1
1395 [ -f dir1/syslog.0 ] || exit 1
1396 [ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
1397 [ -f dir1/syslog.1 ] || exit 1
1398 [ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
1399 [ -f dir1/syslog.2 ] || exit 1
1400 [ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
1401 [ -f dir1/syslog.3 ] || exit 1
1402 [ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
1403 [ -f dir1/syslog.4 ] || exit 1
1404 [ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
1405 [ -f dir1/syslog.5 ] || exit 1
1406 [ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
1407 [ -f dir1/syslog.6 ] || exit 1
1408 [ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
1409 [ -f dir1/syslog.7 ] || exit 1
1410 [ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
1411 [ -f dir1/syslog.8 ] && exit 1
1413 [ -s dir1/notes ] || exit 1
1414 [ "xinitially dir1/notes" = "x`/bin/cat dir1/notes`" ] || exit 1
1415 [ -f dir1/notes.0 ] && exit 1
1417 [ -f dir2/messages ] || exit 1
1418 [ "xinitially dir2/messages" = "x`/bin/cat dir2/messages`" ] || exit 1
1419 [ -f dir2/messages.0 ] || exit 1
1420 [ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.0`" ] || exit 1
1421 [ -f dir2/messages.1 ] || exit 1
1422 [ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.1`" ] || exit 1
1423 [ -f dir2/messages.2 ] || exit 1
1424 [ "xinitially dir2/messages.2" = "x`/bin/cat dir2/messages.2`" ] || exit 1
1425 [ -f dir2/messages.3 ] || exit 1
1426 [ "xinitially dir2/messages.3" = "x`/bin/cat dir2/messages.3`" ] || exit 1
1427 [ -f dir2/messages.4 ] && exit 1
1429 [ -f dir2/log ] || exit 1
1430 [ -s dir2/log ] && exit 1
1431 [ -f dir2/log.0 ] || exit 1
1432 [ "xinitially dir2/log" = "x`/bin/cat dir2/log.0`" ] || exit 1
1433 [ -f dir2/log.1 ] && exit 1
1435 /bin/sed "s/ -P '[^']*' *//" < logadm.timestamps > sed.out
1436 /bin/diff sed.out.expect sed.out || exit 1
1437 /bin/sed -n "s/ -P '[^']*' */<&>/p" < logadm.conf > sed.out
1438 [ -s sed.out ] && exit 1
1439 exit 0
1442 set_file('runtest', <<"EOF");
1443 # test "logadm9"
1444 $envsetup
1445 exec $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err
1449 ###########################################################################
1451 # logadm9d -- test of age check like logadm9, but age is a couple days
1453 ###########################################################################
1454 sub logadm9d {
1455 mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
1456 set_file('dir1/syslog', 'initially dir1/syslog');
1457 set_file('dir1/syslog.0', 'initially dir1/syslog.0');
1458 set_file('dir1/syslog.1', 'initially dir1/syslog.1');
1459 set_file('dir1/syslog.2', 'initially dir1/syslog.2');
1460 set_file('dir1/syslog.3', 'initially dir1/syslog.3');
1461 set_file('dir1/syslog.4', 'initially dir1/syslog.4');
1462 set_file('dir1/syslog.5', 'initially dir1/syslog.5');
1463 set_file('dir1/syslog.6', 'initially dir1/syslog.6');
1464 set_file('dir1/syslog.7', 'initially dir1/syslog.7');
1465 mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
1466 set_file('dir2/messages', 'initially dir2/messages');
1467 set_file('dir2/messages.0', 'initially dir2/messages.0');
1468 set_file('dir2/messages.1', 'initially dir2/messages.1');
1469 set_file('dir2/messages.2', 'initially dir2/messages.2');
1470 set_file('dir2/messages.3', 'initially dir2/messages.3');
1472 $now = time;
1473 $nowstr = gmtime($now);
1474 # a day minus 30 seconds ago...
1475 $closetodaysecs = $now - (60 * 60 * 24 - 30);
1476 $closetoday = gmtime($closetodaysecs);
1477 # a day minus six hours ago...
1478 $lessthandaysecs = $now - (60 * 60 * 24 - 60 * 60 * 6);
1479 $lessthanday = gmtime($lessthandaysecs);
1481 set_file('logadm.conf', <<"EOF");
1482 # now: $nowstr is $now
1483 # $closetoday is $closetodaysecs
1484 dir1/syslog -p 1d -C 8 -P '$closetoday'
1485 # $lessthanday is $lessthandaysecs
1486 dir2/messages -p 1d -C 4 -P '$lessthanday'
1489 set_file('checktest', <<'EOF');
1490 [ -s std.err ] && { cat std.err; exit 1; }
1491 [ -s std.out ] && exit 1
1492 [ -f dir1/syslog ] || exit 1
1493 [ -s dir1/syslog ] && exit 1
1494 [ -f dir1/syslog.0 ] || exit 1
1495 [ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
1496 [ -f dir1/syslog.1 ] || exit 1
1497 [ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
1498 [ -f dir1/syslog.2 ] || exit 1
1499 [ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
1500 [ -f dir1/syslog.3 ] || exit 1
1501 [ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
1502 [ -f dir1/syslog.4 ] || exit 1
1503 [ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
1504 [ -f dir1/syslog.5 ] || exit 1
1505 [ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
1506 [ -f dir1/syslog.6 ] || exit 1
1507 [ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
1508 [ -f dir1/syslog.7 ] || exit 1
1509 [ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
1510 [ -f dir1/syslog.8 ] && exit 1
1512 [ -f dir2/messages ] || exit 1
1513 [ "xinitially dir2/messages" = "x`/bin/cat dir2/messages`" ] || exit 1
1514 [ -f dir2/messages.0 ] || exit 1
1515 [ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.0`" ] || exit 1
1516 [ -f dir2/messages.1 ] || exit 1
1517 [ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.1`" ] || exit 1
1518 [ -f dir2/messages.2 ] || exit 1
1519 [ "xinitially dir2/messages.2" = "x`/bin/cat dir2/messages.2`" ] || exit 1
1520 [ -f dir2/messages.3 ] || exit 1
1521 [ "xinitially dir2/messages.3" = "x`/bin/cat dir2/messages.3`" ] || exit 1
1522 [ -f dir2/messages.4 ] && exit 1
1523 exit 0
1526 set_file('runtest', <<"EOF");
1527 # test "logadm9d"
1528 $envsetup
1529 exec $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err
1533 ###########################################################################
1535 # logadm10 -- test of size-based rotation check
1537 ###########################################################################
1538 sub logadm10 {
1539 mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
1540 set_file('dir1/syslog', 'initially dir1/syslogXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
1541 set_file('dir1/syslog.0', 'initially dir1/syslog.0');
1542 set_file('dir1/syslog.1', 'initially dir1/syslog.1');
1543 set_file('dir1/syslog.2', 'initially dir1/syslog.2');
1544 set_file('dir1/syslog.3', 'initially dir1/syslog.3');
1545 set_file('dir1/syslog.4', 'initially dir1/syslog.4');
1546 set_file('dir1/syslog.5', 'initially dir1/syslog.5');
1547 set_file('dir1/syslog.6', 'initially dir1/syslog.6');
1548 set_file('dir1/syslog.7', 'initially dir1/syslog.7');
1549 mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
1550 set_file('dir2/messages', 'initially dir2/messages');
1551 set_file('dir2/messages.0', 'initially dir2/messages.0');
1552 set_file('dir2/messages.1', 'initially dir2/messages.1');
1553 set_file('dir2/messages.2', 'initially dir2/messages.2');
1554 set_file('dir2/messages.3', 'initially dir2/messages.3');
1556 set_file('logadm.conf', <<"EOF");
1557 dir1/syslog -C 8 -s 30b
1558 dir2/messages -C 4 -s 30b
1561 set_file('checktest', <<'EOF');
1562 [ -s std.err ] && { cat std.err; exit 1; }
1563 [ -s std.out ] && exit 1
1564 [ -f dir1/syslog ] || exit 1
1565 [ -s dir1/syslog ] && exit 1
1566 [ -f dir1/syslog.0 ] || exit 1
1567 [ "xinitially dir1/syslogXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
1568 [ -f dir1/syslog.1 ] || exit 1
1569 [ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
1570 [ -f dir1/syslog.2 ] || exit 1
1571 [ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
1572 [ -f dir1/syslog.3 ] || exit 1
1573 [ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
1574 [ -f dir1/syslog.4 ] || exit 1
1575 [ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
1576 [ -f dir1/syslog.5 ] || exit 1
1577 [ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
1578 [ -f dir1/syslog.6 ] || exit 1
1579 [ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
1580 [ -f dir1/syslog.7 ] || exit 1
1581 [ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
1582 [ -f dir1/syslog.8 ] && exit 1
1584 [ -f dir2/messages ] || exit 1
1585 [ "xinitially dir2/messages" = "x`/bin/cat dir2/messages`" ] || exit 1
1586 [ -f dir2/messages.0 ] || exit 1
1587 [ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.0`" ] || exit 1
1588 [ -f dir2/messages.1 ] || exit 1
1589 [ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.1`" ] || exit 1
1590 [ -f dir2/messages.2 ] || exit 1
1591 [ "xinitially dir2/messages.2" = "x`/bin/cat dir2/messages.2`" ] || exit 1
1592 [ -f dir2/messages.3 ] || exit 1
1593 [ "xinitially dir2/messages.3" = "x`/bin/cat dir2/messages.3`" ] || exit 1
1594 [ -f dir2/messages.4 ] && exit 1
1595 exit 0
1598 set_file('runtest', <<"EOF");
1599 # test "logadm10"
1600 $envsetup
1601 exec $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err
1605 ###########################################################################
1607 # logadm11 -- test of size-based expiration check
1609 ###########################################################################
1610 sub logadm11 {
1611 mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
1612 set_file('dir1/syslog', 'initially dir1/syslog');
1613 set_file('dir1/syslog.0', 'initially dir1/syslog.0');
1614 set_file('dir1/syslog.1', 'initially dir1/syslog.1');
1615 set_file('dir1/syslog.2', 'initially dir1/syslog.2');
1616 set_file('dir1/syslog.3', 'initially dir1/syslog.3');
1617 set_file('dir1/syslog.4', 'initially dir1/syslog.4');
1618 set_file('dir1/syslog.5', 'initially dir1/syslog.5');
1619 set_file('dir1/syslog.6', 'initially dir1/syslog.6');
1620 set_file('dir1/syslog.7', 'initially dir1/syslog.7');
1621 mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
1622 set_file('dir2/messages', 'initially dir2/messages');
1623 set_file('dir2/messages.0', 'initially dir2/messages.0');
1624 set_file('dir2/messages.1', 'initially dir2/messages.1');
1625 set_file('dir2/messages.2', 'initially dir2/messages.2');
1626 set_file('dir2/messages.3', 'initially dir2/messages.3');
1628 set_file('logadm.conf', <<"EOF");
1629 dir1/syslog -C 8 -s 30b -S 75b
1630 dir2/messages -C 4 -s 30b -S 75b
1633 set_file('checktest', <<'EOF');
1634 [ -s std.err ] && { cat std.err; exit 1; }
1635 [ -s std.out ] && exit 1
1636 [ -f dir1/syslog ] || exit 1
1637 [ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog`" ] || exit 1
1638 [ -f dir1/syslog.0 ] || exit 1
1639 [ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
1640 [ -f dir1/syslog.1 ] || exit 1
1641 [ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
1642 [ -f dir1/syslog.2 ] || exit 1
1643 [ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
1644 [ -f dir1/syslog.3 ] && exit 1
1645 [ -f dir1/syslog.4 ] && exit 1
1646 [ -f dir1/syslog.5 ] && exit 1
1647 [ -f dir1/syslog.6 ] && exit 1
1648 [ -f dir1/syslog.7 ] && exit 1
1649 [ -f dir1/syslog.8 ] && exit 1
1651 [ -f dir2/messages ] || exit 1
1652 [ "xinitially dir2/messages" = "x`/bin/cat dir2/messages`" ] || exit 1
1653 [ -f dir2/messages.0 ] || exit 1
1654 [ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.0`" ] || exit 1
1655 [ -f dir2/messages.1 ] || exit 1
1656 [ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.1`" ] || exit 1
1657 [ -f dir2/messages.2 ] || exit 1
1658 [ "xinitially dir2/messages.2" = "x`/bin/cat dir2/messages.2`" ] || exit 1
1659 [ -f dir2/messages.3 ] && exit 1
1660 [ -f dir2/messages.4 ] && exit 1
1661 exit 0
1664 set_file('runtest', <<"EOF");
1665 # test "logadm11"
1666 $envsetup
1667 exec $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err
1671 ###########################################################################
1673 # logadm12 -- ENOENT error path
1675 ###########################################################################
1676 sub logadm12 {
1677 set_file('std.err.expect', <<'EOF');
1678 logadm: Warning: logfile: No such file or directory
1681 set_file('checktest', <<"EOF");
1682 [ -s std.out ] && exit 1
1683 exec /bin/diff std.err.expect std.err
1686 set_file('runtest', <<"EOF");
1687 # test "logadm12"
1688 $envsetup
1689 exec $bindir/logadm -f /dev/null logfile >std.out 2>std.err
1693 ###########################################################################
1695 # logadm13 -- ENOENT error path with -N flag
1697 ###########################################################################
1698 sub logadm13 {
1699 set_file('checktest', <<"EOF");
1700 [ -s std.err ] && { cat std.err; exit 1; }
1701 [ -s std.out ] && exit 1
1702 exit 0
1705 set_file('runtest', <<"EOF");
1706 # test "logadm13"
1707 $envsetup
1708 exec $bindir/logadm -N -f /dev/null logfile >std.out 2>std.err
1712 ###########################################################################
1714 # logadm14 -- test of -n and -v flags
1716 ###########################################################################
1717 sub logadm14 {
1718 mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
1719 set_file('dir1/syslog', 'initially dir1/syslog');
1720 set_file('dir1/syslog.0', 'initially dir1/syslog.0');
1721 set_file('dir1/syslog.1', 'initially dir1/syslog.1');
1722 set_file('dir1/syslog.2', 'initially dir1/syslog.2');
1723 set_file('dir1/syslog.3', 'initially dir1/syslog.3');
1724 set_file('dir1/syslog.4', 'initially dir1/syslog.4');
1725 set_file('dir1/syslog.5', 'initially dir1/syslog.5');
1726 set_file('dir1/syslog.6', 'initially dir1/syslog.6');
1727 set_file('dir1/syslog.7', 'initially dir1/syslog.7');
1728 mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
1729 set_file('dir2/messages', 'initially dir2/messages');
1730 set_file('dir2/messages.0', 'initially dir2/messages.0');
1731 set_file('dir2/messages.1', 'initially dir2/messages.1');
1732 set_file('dir2/messages.2', 'initially dir2/messages.2');
1733 set_file('dir2/messages.3', 'initially dir2/messages.3');
1735 set_file('logadm.conf', <<'EOF');
1737 # logadm.conf
1739 # Default settings for system log file management.
1740 # The -w option to logadm(1M) is the preferred way to write to this file,
1741 # but if you do edit it by hand, use "logadm -V" to check it for errors.
1742 # but if you do edit it by hand, use "logadm -V" to check it for errors.
1744 # The format of lines in this file is:
1745 # <logname> <options>
1746 # For each logname listed here, the default options to logadm
1747 # are given. Options given on the logadm command line override
1748 # the defaults contained in this file.
1750 # logadm typically runs early every morning via an entry in
1751 # root's crontab (see crontab(1)).
1753 dir1/syslog -C 8 -a 'echo kill -HUP `cat /var/run/*syslog*pid` >> cmd.out'
1754 dir2/messages -C 4 -a 'echo kill -HUP `cat /var/run/*syslog*pid` >> cmd.out'
1756 # The entry below is used by turnacct(1M)
1758 /var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
1761 $gid = $);
1762 $gid =~ s/ .*//;
1763 set_file('grep.out.expect', <<'EOF'.<<"EOF".<<'EOF'.<<"EOF".<<'EOF');
1764 # loading logadm.conf
1765 # processing logname: dir1/syslog
1766 # using default rotate rules: -s1b -p1w
1767 # using default template: $file.$n
1768 mkdir -p dir1 # verify directory exists
1769 mv -f dir1/syslog.7 dir1/syslog.8 # rotate log file
1770 mkdir -p dir1 # verify directory exists
1771 mv -f dir1/syslog.6 dir1/syslog.7 # rotate log file
1772 mkdir -p dir1 # verify directory exists
1773 mv -f dir1/syslog.5 dir1/syslog.6 # rotate log file
1774 mkdir -p dir1 # verify directory exists
1775 mv -f dir1/syslog.4 dir1/syslog.5 # rotate log file
1776 mkdir -p dir1 # verify directory exists
1777 mv -f dir1/syslog.3 dir1/syslog.4 # rotate log file
1778 mkdir -p dir1 # verify directory exists
1779 mv -f dir1/syslog.2 dir1/syslog.3 # rotate log file
1780 mkdir -p dir1 # verify directory exists
1781 mv -f dir1/syslog.1 dir1/syslog.2 # rotate log file
1782 mkdir -p dir1 # verify directory exists
1783 mv -f dir1/syslog.0 dir1/syslog.1 # rotate log file
1784 mkdir -p dir1 # verify directory exists
1785 mv -f dir1/syslog dir1/syslog.0 # rotate log file
1786 touch dir1/syslog
1788 chown $>:$gid dir1/syslog
1790 chmod 664 dir1/syslog
1791 # processing logname: dir2/messages
1792 # using default rotate rules: -s1b -p1w
1793 # using default template: $file.$n
1794 mkdir -p dir2 # verify directory exists
1795 mv -f dir2/messages.3 dir2/messages.4 # rotate log file
1796 mkdir -p dir2 # verify directory exists
1797 mv -f dir2/messages.2 dir2/messages.3 # rotate log file
1798 mkdir -p dir2 # verify directory exists
1799 mv -f dir2/messages.1 dir2/messages.2 # rotate log file
1800 mkdir -p dir2 # verify directory exists
1801 mv -f dir2/messages.0 dir2/messages.1 # rotate log file
1802 mkdir -p dir2 # verify directory exists
1803 mv -f dir2/messages dir2/messages.0 # rotate log file
1804 touch dir2/messages
1806 chown $>:$gid dir2/messages
1808 chmod 664 dir2/messages
1809 # processing logname: /var/adm/pacct
1810 # using default template: $file.$n
1811 sh -c echo kill -HUP `cat /var/run/*syslog*pid` >> cmd.out # -a cmd
1812 # logadm.conf and logadm.timestamps unchanged
1815 set_file('checktest', <<'EOF');
1816 [ -s std.err ] && { cat std.err; exit 1; }
1817 [ -f std.out ] || exit 1
1818 [ -f dir1/syslog ] || exit 1
1819 [ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog`" ] || exit 1
1820 [ -f dir1/syslog.0 ] || exit 1
1821 [ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
1822 [ -f dir1/syslog.1 ] || exit 1
1823 [ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
1824 [ -f dir1/syslog.2 ] || exit 1
1825 [ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
1826 [ -f dir1/syslog.3 ] || exit 1
1827 [ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
1828 [ -f dir1/syslog.4 ] || exit 1
1829 [ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
1830 [ -f dir1/syslog.5 ] || exit 1
1831 [ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
1832 [ -f dir1/syslog.6 ] || exit 1
1833 [ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
1834 [ -f dir1/syslog.7 ] || exit 1
1835 [ "xinitially dir1/syslog.7" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
1836 [ -f dir1/syslog.8 ] && exit 1
1838 [ -f dir2/messages ] || exit 1
1839 [ "xinitially dir2/messages" = "x`/bin/cat dir2/messages`" ] || exit 1
1840 [ -f dir2/messages.0 ] || exit 1
1841 [ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.0`" ] || exit 1
1842 [ -f dir2/messages.1 ] || exit 1
1843 [ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.1`" ] || exit 1
1844 [ -f dir2/messages.2 ] || exit 1
1845 [ "xinitially dir2/messages.2" = "x`/bin/cat dir2/messages.2`" ] || exit 1
1846 [ -f dir2/messages.3 ] || exit 1
1847 [ "xinitially dir2/messages.3" = "x`/bin/cat dir2/messages.3`" ] || exit 1
1848 [ -f dir2/messages.4 ] && exit 1
1849 /bin/grep -v 'recording rotation date' std.out > grep.out
1850 exec /bin/diff grep.out.expect grep.out
1853 set_file('runtest', <<"EOF");
1854 # test "logadm14"
1855 $envsetup
1856 exec $bindir/logadm -nv -f logadm.conf -F logadm.timestamps >std.out 2>std.err
1860 ###########################################################################
1862 # logadm15 -- test of -T
1864 ###########################################################################
1865 sub logadm15 {
1866 set_file('logfile', '');
1867 set_file('logfile.0', 'initially logfile.0');
1868 set_file('logfile.1', 'initially logfile.1');
1869 set_file('logfile.2', 'initially logfile.2');
1870 set_file('logfile.3', 'initially logfile.3');
1871 set_file('logfile.4', 'initially logfile.4');
1872 set_file('logfile.5', 'initially logfile.5');
1873 set_file('logfile.6', 'initially logfile.6');
1874 set_file('logfile.7', 'initially logfile.7');
1875 set_file('logfile.8', 'initially logfile.8');
1876 set_file('logfile.9', 'initially logfile.9');
1878 set_file('checktest', <<'EOF');
1879 [ -s std.err ] && { cat std.err; exit 1; }
1880 [ -s std.out ] && exit 1
1881 [ -f logfile ] || exit 1
1882 [ "x" = "x`/bin/cat logfile`" ] || exit 1
1883 [ -f logfile.0 ] || exit 1
1884 [ "xinitially logfile.0" = "x`/bin/cat logfile.0`" ] || exit 1
1885 [ -f logfile.1 ] || exit 1
1886 [ "xinitially logfile.1" = "x`/bin/cat logfile.1`" ] || exit 1
1887 [ -f logfile.2 ] || exit 1
1888 [ "xinitially logfile.2" = "x`/bin/cat logfile.2`" ] || exit 1
1889 [ -f logfile.3 ] && exit 1
1890 [ -f logfile.4 ] || exit 1
1891 [ "xinitially logfile.4" = "x`/bin/cat logfile.4`" ] || exit 1
1892 [ -f logfile.5 ] && exit 1
1893 [ -f logfile.6 ] || exit 1
1894 [ "xinitially logfile.6" = "x`/bin/cat logfile.6`" ] || exit 1
1895 [ -f logfile.7 ] && exit 1
1896 [ -f logfile.8 ] || exit 1
1897 [ "xinitially logfile.8" = "x`/bin/cat logfile.8`" ] || exit 1
1898 [ -f logfile.9 ] && exit 1
1899 [ -f logfile.10 ] && exit 1
1900 exit 0
1903 set_file('runtest', <<"EOF");
1904 # test "logadm15"
1905 $envsetup
1906 exec $bindir/logadm -f /dev/null logfile -C1 -T '*.[13579]'>std.out 2>std.err
1910 ###########################################################################
1912 # logadm16 -- test of -h
1914 ###########################################################################
1915 sub logadm16 {
1916 set_file('std.err.expect', <<'EOF');
1917 Usage: logadm [options]
1918 (processes all entries in /etc/logadm.conf or conffile given by -f)
1919 or: logadm [options] logname...
1920 (processes the given lognames)
1922 General options:
1923 -e mailaddr mail errors to given address
1924 -F timestamps use timestamps instead of /var/logadm/timestamps
1925 -f conffile use conffile instead of /etc/logadm.conf
1926 -h display help
1927 -N not an error if log file nonexistent
1928 -n show actions, don't perform them
1929 -r remove logname entry from conffile
1930 -V ensure conffile entries exist, correct
1931 -v print info about actions happening
1932 -w entryname write entry to config file
1934 Options which control when a logfile is rotated:
1935 (default is: -s1b -p1w if no -s or -p)
1936 -p period only rotate if period passed since last rotate
1937 -P timestamp used to store rotation date in conffile
1938 -s size only rotate if given size or greater
1940 Options which control how a logfile is rotated:
1941 (default is: -t '$file.$n', owner/group/mode taken from log file)
1942 -a cmd execute cmd after taking actions
1943 -b cmd execute cmd before taking actions
1944 -c copy & truncate logfile, don't rename
1945 -g group new empty log file group
1946 -l rotate log file with local time rather than UTC
1947 -m mode new empty log file mode
1948 -M cmd execute cmd to rotate the log file
1949 -o owner new empty log file owner
1950 -R cmd run cmd on file after rotate
1951 -t template template for naming old logs
1952 -z count gzip old logs except most recent count
1954 Options which control the expiration of old logfiles:
1955 (default is: -C10 if no -A, -C, or -S)
1956 -A age expire logs older than age
1957 -C count expire old logs until count remain
1958 -E cmd run cmd on file to expire
1959 -S size expire until space used is below size
1960 -T pattern pattern for finding old logs
1963 set_file('checktest', <<'EOF');
1964 [ -s std.out ] && exit 1
1965 exec /bin/diff std.err.expect std.err
1968 set_file('runtest', <<"EOF");
1969 # test "logadm16"
1970 $envsetup
1971 exec $bindir/logadm -h >std.out 2>std.err
1975 ###########################################################################
1977 # logadm17 -- test that mkdir -p happens as necessary
1979 ###########################################################################
1980 sub logadm17 {
1981 set_file('logfile', 'initially logfile');
1983 set_file('checktest', <<'EOF');
1984 [ -s std.err ] && { cat std.err; exit 1; }
1985 [ -s std.out ] && exit 1
1986 [ -f dir1/dir2/logfile ] || exit 1
1987 [ -f logfile ] || exit 1
1988 [ "xinitially logfile" = "x`/bin/cat dir1/dir2/logfile`" ] || exit 1
1989 exit 0
1992 set_file('runtest', <<"EOF");
1993 # test "logadm17"
1994 $envsetup
1995 exec $bindir/logadm -f /dev/null -t 'dir1/dir2/\$basename' logfile -p now >std.out 2>std.err
1999 ###########################################################################
2001 # logadm18 -- test of -M option
2003 ###########################################################################
2004 sub logadm18 {
2005 mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
2006 set_file('dir1/syslog', 'initially dir1/syslog');
2007 set_file('dir1/syslog.0', 'initially dir1/syslog.0');
2008 set_file('dir1/syslog.1', 'initially dir1/syslog.1');
2009 set_file('dir1/syslog.2', 'initially dir1/syslog.2');
2010 set_file('dir1/syslog.3', 'initially dir1/syslog.3');
2011 set_file('dir1/syslog.4', 'initially dir1/syslog.4');
2012 set_file('dir1/syslog.5', 'initially dir1/syslog.5');
2013 set_file('dir1/syslog.6', 'initially dir1/syslog.6');
2014 set_file('dir1/syslog.7', 'initially dir1/syslog.7');
2016 set_file('logadm.conf', <<"EOF");
2017 dir1/syslog -C 8 -s 1b -M '/bin/tr [a-z] [A-Z] < \$file > \$nfile; /bin/rm -f \$file'
2020 set_file('checktest', <<'EOF');
2021 [ -s std.err ] && { cat std.err; exit 1; }
2022 [ -s std.out ] && exit 1
2023 [ -f dir1/syslog ] || exit 1
2024 [ -s dir1/syslog ] && exit 1
2025 [ -f dir1/syslog.0 ] || exit 1
2026 [ "xINITIALLY DIR1/SYSLOG" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
2027 [ -f dir1/syslog.1 ] || exit 1
2028 [ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
2029 [ -f dir1/syslog.2 ] || exit 1
2030 [ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
2031 [ -f dir1/syslog.3 ] || exit 1
2032 [ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
2033 [ -f dir1/syslog.4 ] || exit 1
2034 [ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
2035 [ -f dir1/syslog.5 ] || exit 1
2036 [ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
2037 [ -f dir1/syslog.6 ] || exit 1
2038 [ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
2039 [ -f dir1/syslog.7 ] || exit 1
2040 [ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
2041 [ -f dir1/syslog.8 ] && exit 1
2043 exit 0
2046 set_file('runtest', <<"EOF");
2047 # test "logadm18"
2048 $envsetup
2049 exec $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err
2053 #############################################################################
2055 # logadm19 -- test of -l
2057 #############################################################################
2058 sub logadm19 {
2059 set_file('logfile', 'initially logfile');
2061 set_file('checktest', <<'EOF');
2062 [ -s std.err ] && { cat std.err; exit 1; }
2063 [ -s std.out ] && exit 1
2064 [ -s logfile ] && exit 1
2065 TZ= export TZ
2066 d=`/bin/date +\%d\%H\%M`
2067 [ -f logfile.$d ] || exit 1
2068 [ "xinitially logfile" = "x`/bin/cat logfile.$d`" ] || exit 1
2069 exit 0
2072 set_file('runtest', <<"EOF");
2073 # test "logadm19"
2074 $envsetup
2075 exec $bindir/logadm -f /dev/null -l -p now logfile -t '\$file.\%d\%H\%M' >std.out 2>std.err
2079 #############################################################################
2081 # logadm20 -- test of unquotables/error handling
2083 #############################################################################
2084 sub logadm20 {
2085 set_file('logadm.conf', <<'EOF');
2086 # non-trivial entry
2087 /var/log/syslog -C 8 -a 'kill -HUP `cat /var/run/*syslog*pid`'
2090 set_file('std.err.expect', <<'EOF');
2091 logadm: Error: Can't protect quotes in </bin/echo "She can't take anymore, Cap'n!">
2092 logadm: Error: unsafe to update configuration file or timestamps
2093 logadm: Error: bailing out due to command line errors
2094 Use "logadm -h" for help.
2095 exit=1
2098 set_file('checktest', <<'EOF');
2099 [ -s std.err ] || exit 1
2100 [ -s std.out ] && exit 1
2101 [ -f logadm.conf????? ] && exit 1
2102 [ -f logadm.timestamps????? ] && exit 1
2103 exec /bin/diff std.err.expect std.err
2106 set_file('runtest', <<"EOF");
2107 # test "logadm20"
2108 $envsetup
2109 $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
2110 echo exit=\$? >>std.err
2114 #############################################################################
2116 # logadm21 -- test of busted configuration file
2118 #############################################################################
2119 sub logadm21 {
2120 set_file('logadm.conf', <<'EOF');
2121 poop
2123 set_file('checktest', <<'EOF');
2124 [ -s std.err ] || exit 1
2125 grep Warning std.err > /dev/null
2128 set_file('runtest', <<"EOF");
2129 # test "logadm21"
2130 $envsetup
2131 $bindir/logadm -f logadm.conf 2>std.err
2132 exit 0