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