xref: /onnv-gate/usr/src/cmd/logadm/tester (revision 12986:04c3fb904c79)
10Sstevel@tonic-gate#!/usr/bin/perl -w
20Sstevel@tonic-gate#
30Sstevel@tonic-gate# CDDL HEADER START
40Sstevel@tonic-gate#
50Sstevel@tonic-gate# The contents of this file are subject to the terms of the
61511Sdp# Common Development and Distribution License (the "License").
71511Sdp# You may not use this file except in compliance with the License.
80Sstevel@tonic-gate#
90Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate# See the License for the specific language governing permissions
120Sstevel@tonic-gate# and limitations under the License.
130Sstevel@tonic-gate#
140Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate#
200Sstevel@tonic-gate# CDDL HEADER END
210Sstevel@tonic-gate#
220Sstevel@tonic-gate#
23*12986SJohn.Zolnowsky@Sun.COM# Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
240Sstevel@tonic-gate#
250Sstevel@tonic-gate#
260Sstevel@tonic-gate# tester - run logadm tests
270Sstevel@tonic-gate#
280Sstevel@tonic-gate# requires a <bindir> argument to say where the various logadm
290Sstevel@tonic-gate# binaries live (conftest, globtest, kwtest, luttest, optstest, and
300Sstevel@tonic-gate# logadm itself).
310Sstevel@tonic-gate#
320Sstevel@tonic-gate# to run all the tests:
330Sstevel@tonic-gate# 	tester [-f] <bindir>
340Sstevel@tonic-gate#
350Sstevel@tonic-gate# to run just a few tests, given their names:
360Sstevel@tonic-gate# 	tester [-f] <bindir> globtest1 luttest1
370Sstevel@tonic-gate#
380Sstevel@tonic-gate# to setup a test and stop so you can run it by hand:
390Sstevel@tonic-gate# 	tester [-f] -s globtest1 <bindir>
400Sstevel@tonic-gate#
410Sstevel@tonic-gate# 	tester will tell you what tmp directory it created for
420Sstevel@tonic-gate# 	the test.  to run it, cd there and run:
430Sstevel@tonic-gate# 		sh runtest
440Sstevel@tonic-gate# 	to check the results, run:
450Sstevel@tonic-gate# 		sh checktest
460Sstevel@tonic-gate#
470Sstevel@tonic-gate# -f means "fast" -- without it, watchmalloc(3MALLOC) is setup for
480Sstevel@tonic-gate# each test and they run a zillion times slower and produce core
490Sstevel@tonic-gate# dumps when malloc/free problems are detected.
500Sstevel@tonic-gate#
510Sstevel@tonic-gate$watchmalloc=1;		# default is to use watchmalloc
520Sstevel@tonic-gate${ENV} = "/bin";
530Sstevel@tonic-gateumask 002;
540Sstevel@tonic-gate
550Sstevel@tonic-gate# list of tests we run by default
560Sstevel@tonic-gate@tests = (
570Sstevel@tonic-gate	"conftest1",
580Sstevel@tonic-gate	"conftest2",
590Sstevel@tonic-gate	"globtest1",
600Sstevel@tonic-gate	"globtest2",
610Sstevel@tonic-gate	"kwtest1",
620Sstevel@tonic-gate	"kwtest2",
630Sstevel@tonic-gate	"luttest1",
640Sstevel@tonic-gate	"optstest1",
650Sstevel@tonic-gate	"optstest2",
660Sstevel@tonic-gate	"logadmV1",
670Sstevel@tonic-gate	"logadmV2",
680Sstevel@tonic-gate	"logadmr",
690Sstevel@tonic-gate	"logadmw",
700Sstevel@tonic-gate	"logadm1",
710Sstevel@tonic-gate	"logadm1c",
720Sstevel@tonic-gate	"logadm2",
730Sstevel@tonic-gate	"logadm3",
740Sstevel@tonic-gate	"logadm4",
750Sstevel@tonic-gate	"logadm5",
760Sstevel@tonic-gate	"logadm6",
770Sstevel@tonic-gate	"logadm7",
780Sstevel@tonic-gate	"logadm8",
790Sstevel@tonic-gate	"logadm9",
800Sstevel@tonic-gate	"logadm9d",
810Sstevel@tonic-gate	"logadm10",
820Sstevel@tonic-gate	"logadm11",
830Sstevel@tonic-gate	"logadm12",
840Sstevel@tonic-gate	"logadm13",
850Sstevel@tonic-gate	"logadm14",
860Sstevel@tonic-gate	"logadm15",
870Sstevel@tonic-gate	"logadm16",
880Sstevel@tonic-gate	"logadm17",
890Sstevel@tonic-gate	"logadm18",
90954Sgm149974	"logadm19",
91*12986SJohn.Zolnowsky@Sun.COM	"logadm20",
920Sstevel@tonic-gate);
930Sstevel@tonic-gate
940Sstevel@tonic-gateuse Getopt::Std;
950Sstevel@tonic-gateuse File::Find;
960Sstevel@tonic-gate
970Sstevel@tonic-gate$usage_summary = '[-s test-name] [-d dir] bindir [test-name...]';
980Sstevel@tonic-gate$usage_getopts = 'fd:s:';
990Sstevel@tonic-gate%usage = (
1000Sstevel@tonic-gate	d=>'use dir for tests rather than creating one in /tmp',
1010Sstevel@tonic-gate	s=>'setup only, do not run test');
1020Sstevel@tonic-gate
1030Sstevel@tonic-gate# spew usage message, plus any given message, and exit
1040Sstevel@tonic-gatesub usage {
1050Sstevel@tonic-gate	my $msg = shift;
1060Sstevel@tonic-gate
1070Sstevel@tonic-gate	if ($msg) {
1080Sstevel@tonic-gate		chomp $msg;
1090Sstevel@tonic-gate		warn "$0: $msg\n" if $msg;
1100Sstevel@tonic-gate	}
1110Sstevel@tonic-gate	warn "Usage: $0 $usage_summary\n";
1120Sstevel@tonic-gate	foreach (sort keys %usage) {
1130Sstevel@tonic-gate		warn "       -$_ $usage{$_}\n";
1140Sstevel@tonic-gate	}
1150Sstevel@tonic-gate	exit 1;
1160Sstevel@tonic-gate}
1170Sstevel@tonic-gate
1180Sstevel@tonic-gate#
1190Sstevel@tonic-gate# basic argument processing
1200Sstevel@tonic-gate#
1210Sstevel@tonic-gate$myname = $0;
1220Sstevel@tonic-gate$myname =~ s/.*\///;	# just show last component in error mesages
1230Sstevel@tonic-gategetopts($usage_getopts) or usage;
1240Sstevel@tonic-gate$bindir = shift or usage;
1250Sstevel@tonic-gateusage("$bindir does not exist") unless -d $bindir;
1260Sstevel@tonic-gateusage("cannot list more than one test with -s option") if $opt_s && @ARGV;
1270Sstevel@tonic-gate@tests = @ARGV if @ARGV;
1280Sstevel@tonic-gateprint "Fast mode\n" if $opt_f;
1290Sstevel@tonic-gate$watchmalloc = 0 if $opt_f;
1300Sstevel@tonic-gate
1310Sstevel@tonic-gate$mydir=`pwd`;
1320Sstevel@tonic-gatechomp $mydir;
1330Sstevel@tonic-gate
1340Sstevel@tonic-gate$dir = $opt_d;
1350Sstevel@tonic-gate$dir = "/tmp/logadmtest$$" unless $dir = $opt_d;
1360Sstevel@tonic-gate
1370Sstevel@tonic-gateif (!-d $dir) {
1380Sstevel@tonic-gate	mkdir $dir, 0777 or die "$myname: mkdir $dir: $!\n";
1390Sstevel@tonic-gate	$needrmdir = 1;
1400Sstevel@tonic-gate}
1410Sstevel@tonic-gate
1420Sstevel@tonic-gatechdir $dir or die "$myname: $dir: $!\n";
1430Sstevel@tonic-gate
1440Sstevel@tonic-gate# common commands in runtest by tests
1450Sstevel@tonic-gateif ($watchmalloc) {
1460Sstevel@tonic-gate	$envsetup =
1470Sstevel@tonic-gate		"HOME=$dir export HOME; " .
1480Sstevel@tonic-gate		"LD_PRELOAD=watchmalloc.so.1 export LD_PRELOAD; " .
1490Sstevel@tonic-gate		"MALLOC_DEBUG=RW export MALLOC_DEBUG";
1500Sstevel@tonic-gate} else {
1510Sstevel@tonic-gate	$envsetup = "HOME=$dir export HOME; ";
1520Sstevel@tonic-gate}
1530Sstevel@tonic-gate
1540Sstevel@tonic-gate$| = 1;		# a.k.a. setbuf(stdout, NULL)
1550Sstevel@tonic-gate
1560Sstevel@tonic-gateif ($opt_s) {
1570Sstevel@tonic-gate	#
1580Sstevel@tonic-gate	# just setup the test, explain how to use it, and exit
1590Sstevel@tonic-gate	#
1600Sstevel@tonic-gate	$testname = $opt_s;
1610Sstevel@tonic-gate	eval "&$opt_s";
1620Sstevel@tonic-gate	die "$myname: ERROR: $@" if $@;
1630Sstevel@tonic-gate	print "$myname: $testname setup complete, to run, cd to:\n";
1640Sstevel@tonic-gate	print "    $dir\n";
1650Sstevel@tonic-gate	print "and run the command:\n";
1660Sstevel@tonic-gate	print "    sh runtest\n";
1670Sstevel@tonic-gate	print "to check the results, run the command:\n";
1680Sstevel@tonic-gate	print "    sh checktest\n";
1690Sstevel@tonic-gate	exit 0;
1700Sstevel@tonic-gate} else {
1710Sstevel@tonic-gate	#
1720Sstevel@tonic-gate	# run all the tests
1730Sstevel@tonic-gate	#
1740Sstevel@tonic-gate	foreach (@tests) {
1750Sstevel@tonic-gate		$testname = $_;
1760Sstevel@tonic-gate		print "Running $testname...";
1770Sstevel@tonic-gate		eval "&$_";
1780Sstevel@tonic-gate		if ($@) {
1790Sstevel@tonic-gate			print " SETUP FAILURE\n";
1800Sstevel@tonic-gate			print STDERR "$myname: ERROR: $@";
1810Sstevel@tonic-gate			exit 1;
1820Sstevel@tonic-gate		}
1830Sstevel@tonic-gate		eval "runner('runtest')";
1840Sstevel@tonic-gate		if ($@) {
1850Sstevel@tonic-gate			print " RUNTEST FAILURE\n";
1860Sstevel@tonic-gate			print STDERR "$myname: ERROR: $@";
1870Sstevel@tonic-gate			print STDERR "results captured in directory $dir\n";
1880Sstevel@tonic-gate			print STDERR "  or use: $myname -s $testname $bindir\n";
1890Sstevel@tonic-gate			print STDERR "  to do a fresh setup of this test.\n";
1900Sstevel@tonic-gate			exit 1;
1910Sstevel@tonic-gate		}
192*12986SJohn.Zolnowsky@Sun.COM		eval "runner('checktest', '-x', '> checktest.out 2>&1')";
1930Sstevel@tonic-gate		if ($@) {
1940Sstevel@tonic-gate			print " CHECKTEST FAILURE\n";
1950Sstevel@tonic-gate			print STDERR "$myname: ERROR: $@";
196*12986SJohn.Zolnowsky@Sun.COM			print STDERR "results captured in file $dir/checktest.out\n";
1970Sstevel@tonic-gate			print STDERR "  or use: $myname -s $testname $bindir\n";
1980Sstevel@tonic-gate			print STDERR "  to do a fresh setup of this test.\n";
1990Sstevel@tonic-gate			exit 1;
2000Sstevel@tonic-gate		}
2010Sstevel@tonic-gate		print "pass\n";
2020Sstevel@tonic-gate		# sanity...
2030Sstevel@tonic-gate		die "unexpected dir $dir" unless $dir =~ m,/.+/,;
2040Sstevel@tonic-gate		system("/bin/rm -rf $dir/*");
2050Sstevel@tonic-gate	}
2060Sstevel@tonic-gate}
2070Sstevel@tonic-gate
2080Sstevel@tonic-gate# if we were the ones who created $dir, remove it
2090Sstevel@tonic-gateif ($needrmdir) {
2100Sstevel@tonic-gate	chdir $mydir;
2110Sstevel@tonic-gate	rmdir $dir || die "$myname: rmdir $dir: $!\n";
2120Sstevel@tonic-gate}
2130Sstevel@tonic-gate
2140Sstevel@tonic-gateexit 0;
2150Sstevel@tonic-gate
2160Sstevel@tonic-gate#
2170Sstevel@tonic-gate# run a shell script and check for failure
2180Sstevel@tonic-gate#
2190Sstevel@tonic-gate# the shell scripts generated by this program always "exec" the binary
2200Sstevel@tonic-gate# under test so checking here are for exit code, signals, and core dump
2210Sstevel@tonic-gate# is actually checking the program under test and not /bin/sh
2220Sstevel@tonic-gate#
2230Sstevel@tonic-gatesub runner {
224*12986SJohn.Zolnowsky@Sun.COM	my ($cmd, $prefix, $suffix) = (@_, '', '');
225*12986SJohn.Zolnowsky@Sun.COM
226*12986SJohn.Zolnowsky@Sun.COM	my $fullcmd = "/bin/sh $prefix $cmd $suffix";
2270Sstevel@tonic-gate	my $rc = 0xffff & system("$fullcmd");
2280Sstevel@tonic-gate
2290Sstevel@tonic-gate	if ($rc == 0) {
2300Sstevel@tonic-gate		return;		# cmd completed normally
2310Sstevel@tonic-gate	} elsif ($rc == 0xff00) {
2320Sstevel@tonic-gate		die "command \"$cmd\" failed: $!\n";
2330Sstevel@tonic-gate	} elsif (($rc & 0xff) == 0) {
2340Sstevel@tonic-gate		$rc >>= 8;
2350Sstevel@tonic-gate		die "command \"$cmd\" exit $rc\n";
2360Sstevel@tonic-gate	} else {
2370Sstevel@tonic-gate		my $coremsg;
2380Sstevel@tonic-gate		$coremsg = " (core dumped)" if ($rc & 0x80);
2390Sstevel@tonic-gate		$rc &= ~0x80;
2400Sstevel@tonic-gate		die "command \"$cmd\" signal $rc$coremsg\n" ;
2410Sstevel@tonic-gate	}
2420Sstevel@tonic-gate}
2430Sstevel@tonic-gate
2440Sstevel@tonic-gate#
2450Sstevel@tonic-gate# set_file(filename [, contents]) -- create a file, optionally with contents
2460Sstevel@tonic-gate#
2470Sstevel@tonic-gatesub set_file {
2480Sstevel@tonic-gate	my $file = shift;
2490Sstevel@tonic-gate	my $contents = shift;
2500Sstevel@tonic-gate
2510Sstevel@tonic-gate	open SF, ">$file" or die "create \"$file\": $!\n";
2520Sstevel@tonic-gate	print SF $contents if defined($contents);
2530Sstevel@tonic-gate	close SF;
2540Sstevel@tonic-gate}
2550Sstevel@tonic-gate
2560Sstevel@tonic-gate#############
2570Sstevel@tonic-gate#############
2580Sstevel@tonic-gate#############    THE TESTS START AFTER HERE...
2590Sstevel@tonic-gate#############
2600Sstevel@tonic-gate#############
2610Sstevel@tonic-gate
2620Sstevel@tonic-gate# common setup step -- create a testfile.conf
2630Sstevel@tonic-gatesub set_testconffile {
2640Sstevel@tonic-gate	my $fname = shift;
2650Sstevel@tonic-gate	$fname = 'testfile.conf' unless defined($fname);
2660Sstevel@tonic-gate
2670Sstevel@tonic-gate	set_file($fname, <<'EOF');
2680Sstevel@tonic-gate#
2690Sstevel@tonic-gate# logadm.conf
2700Sstevel@tonic-gate#
2710Sstevel@tonic-gate# Default settings for system log file management.
2720Sstevel@tonic-gate# The -w option to logadm(1M) is the preferred way to write to this file,
2730Sstevel@tonic-gate# but if you do edit it by hand, use "logadm -V" to check it for errors.
2740Sstevel@tonic-gate#
2750Sstevel@tonic-gate# The format of lines in this file is:
2760Sstevel@tonic-gate#       <logname> <options>
2770Sstevel@tonic-gate# For each logname listed here, the default options to logadm
2780Sstevel@tonic-gate# are given.  Options given on the logadm command line override
2790Sstevel@tonic-gate# the defaults contained in this file.
2800Sstevel@tonic-gate#
2810Sstevel@tonic-gate# logadm typically runs early every morning via an entry in
2820Sstevel@tonic-gate# root's crontab (see crontab(1)).
2830Sstevel@tonic-gate#
2840Sstevel@tonic-gate/var/adm/messages -C 4 -P 'Thu Nov  1 16:56:42 2001' -a 'kill -HUP `cat /var/run/syslog.pid`'
2850Sstevel@tonic-gate/var/cron/log -s 512k -t /var/cron/olog
2860Sstevel@tonic-gate/var/lp/logs/lpsched -C 2 -N -t '$file.$N'
2870Sstevel@tonic-gate#
2880Sstevel@tonic-gate# The entry below is used by turnacct(1M)
2890Sstevel@tonic-gate#
2900Sstevel@tonic-gate/var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
2910Sstevel@tonic-gateapache -C 24 -a '/usr/apache/bin/apachectl graceful' -p 1m -t '/var/apache/old-logs/$basename.%Y-%m' '/var/apache/logs/*{access,error}_log'
2920Sstevel@tonic-gate/var/log/syslog -C 8 -P 'Thu Nov  1 09:16:38 2001' -a 'kill -HUP `cat /var/run/syslog.pid`'
2930Sstevel@tonic-gate/var/apache/logs/access_log -P 'Thu Nov  1 08:27:56 2001'
2940Sstevel@tonic-gate/var/apache/logs/error_log -P 'Thu Nov  1 08:27:56 2001'
2950Sstevel@tonic-gate/var/apache/logs/suexec_log -P 'Thu Nov  1 08:27:56 2001'
2960Sstevel@tonic-gate/var/apache/logs/mod_jserv.log -P 'Thu Nov  1 08:27:56 2001'
2970Sstevel@tonic-gate/var/apache/logs/jserv.log -P 'Thu Nov  1 08:27:56 2001'
2980Sstevel@tonic-gateEOF
2990Sstevel@tonic-gate}
3000Sstevel@tonic-gate
3010Sstevel@tonic-gate
3020Sstevel@tonic-gate###########################################################################
3030Sstevel@tonic-gate#
3040Sstevel@tonic-gate#	conftest1 -- minimal basic test of the conf.c code
3050Sstevel@tonic-gate#
3060Sstevel@tonic-gate###########################################################################
3070Sstevel@tonic-gatesub conftest1 {
3080Sstevel@tonic-gate	set_testconffile;
3090Sstevel@tonic-gate
3100Sstevel@tonic-gate	set_file('checktest', <<'EOF');
311*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
3120Sstevel@tonic-gate/bin/sed '/^conffile <testfile.conf>:$/d' <std.out >sed.out
313*12986SJohn.Zolnowsky@Sun.COMexec /bin/diff testfile.conf sed.out
3140Sstevel@tonic-gateEOF
3150Sstevel@tonic-gate
3160Sstevel@tonic-gate	set_file('runtest', <<"EOF");
3170Sstevel@tonic-gate# test "conftest1"
3180Sstevel@tonic-gate$envsetup
3190Sstevel@tonic-gateexec $bindir/conftest testfile.conf >std.out 2>std.err
3200Sstevel@tonic-gateEOF
3210Sstevel@tonic-gate}
3220Sstevel@tonic-gate
3230Sstevel@tonic-gate###########################################################################
3240Sstevel@tonic-gate#
3250Sstevel@tonic-gate#	conftest2 -- error path through conf.c
3260Sstevel@tonic-gate#
3270Sstevel@tonic-gate###########################################################################
3280Sstevel@tonic-gatesub conftest2 {
3290Sstevel@tonic-gate	set_file('testfile.conf', 'line fragment');
3300Sstevel@tonic-gate
3310Sstevel@tonic-gate	set_file('std.err.expect', <<'EOF');
332*12986SJohn.Zolnowsky@Sun.COMconftest: Warning: file testfile.conf doesn't end with newline, last line ignored.
3330Sstevel@tonic-gateEOF
3340Sstevel@tonic-gate
3350Sstevel@tonic-gate	set_file('checktest', <<'EOF');
336*12986SJohn.Zolnowsky@Sun.COMexec /bin/diff std.err.expect std.err
3370Sstevel@tonic-gateEOF
3380Sstevel@tonic-gate
3390Sstevel@tonic-gate	set_file('runtest', <<"EOF");
3400Sstevel@tonic-gate# test "conftest2"
3410Sstevel@tonic-gate$envsetup
3420Sstevel@tonic-gate$bindir/conftest testfile.conf >std.out 2>std.err || exit 0
3430Sstevel@tonic-gateexit 1
3440Sstevel@tonic-gateEOF
3450Sstevel@tonic-gate}
3460Sstevel@tonic-gate
3470Sstevel@tonic-gate###########################################################################
3480Sstevel@tonic-gate#
3490Sstevel@tonic-gate#	globtest1 -- minimal basic test of the glob.c code
3500Sstevel@tonic-gate#
3510Sstevel@tonic-gate###########################################################################
3520Sstevel@tonic-gatesub globtest1 {
3530Sstevel@tonic-gate	set_file('fileBname12');
3540Sstevel@tonic-gate	sleep 2;	# ensure above name is odler than below name
3550Sstevel@tonic-gate	set_file('fileAname12');
3560Sstevel@tonic-gate	set_file('fileAname1');
3570Sstevel@tonic-gate	set_file('fileAname3');
3580Sstevel@tonic-gate	set_file('fileAname5');
3590Sstevel@tonic-gate	set_file('fileAname7');
3600Sstevel@tonic-gate	set_file('fileAname9');
3610Sstevel@tonic-gate	set_file('fileAname11');
3620Sstevel@tonic-gate	set_file('fileBname0');
3630Sstevel@tonic-gate	set_file('fileBname2');
3640Sstevel@tonic-gate	set_file('fileBname4');
3650Sstevel@tonic-gate	set_file('fileBname6');
3660Sstevel@tonic-gate	set_file('fileBname8');
3670Sstevel@tonic-gate	set_file('fileBname10');
3680Sstevel@tonic-gate	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
3690Sstevel@tonic-gate	mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
3700Sstevel@tonic-gate	mkdir 'dir3', 0777 or die "mkdir dir3: $!\n";
3710Sstevel@tonic-gate	mkdir 'dir1/dirA', 0777 or die "mkdir dir1/dirA: $!\n";
3720Sstevel@tonic-gate	mkdir 'dir1/dirB', 0777 or die "mkdir dir1/dirB: $!\n";
3730Sstevel@tonic-gate	mkdir 'dir1/dirC', 0777 or die "mkdir dir1/dirC: $!\n";
3740Sstevel@tonic-gate	mkdir 'dir2/dirA', 0777 or die "mkdir dir2/dirA: $!\n";
3750Sstevel@tonic-gate	mkdir 'dir2/dirB', 0777 or die "mkdir dir2/dirB: $!\n";
3760Sstevel@tonic-gate	mkdir 'dir2/dirC', 0777 or die "mkdir dir2/dirC: $!\n";
3770Sstevel@tonic-gate	set_file('dir1/fileAname1');
3780Sstevel@tonic-gate	set_file('dir1/fileAname2');
3790Sstevel@tonic-gate	set_file('dir1/fileAname3');
3800Sstevel@tonic-gate	set_file('dir1/fileAname4');
3810Sstevel@tonic-gate	set_file('dir1/fileAname5');
3820Sstevel@tonic-gate	set_file('dir1/fileBname1');
3830Sstevel@tonic-gate	set_file('dir1/fileBname2');
3840Sstevel@tonic-gate	set_file('dir1/fileBname3');
3850Sstevel@tonic-gate	set_file('dir1/fileBname4');
3860Sstevel@tonic-gate	set_file('dir1/fileBname5');
3870Sstevel@tonic-gate	# supply some varying sizes to produce different total size values
3880Sstevel@tonic-gate	set_file('dir1/dirA/fileAname4', '4444');
3890Sstevel@tonic-gate	sleep 2;	# ensure above file is oldest in dirA
3900Sstevel@tonic-gate	set_file('dir1/dirA/fileAname1', '1');
3910Sstevel@tonic-gate	set_file('dir1/dirA/fileAname2', '22');
3920Sstevel@tonic-gate	set_file('dir1/dirA/fileAname3', '333');
3930Sstevel@tonic-gate	set_file('dir1/dirA/fileAname5', '55555');
3940Sstevel@tonic-gate	set_file('dir1/dirA/fileBname1', '1');
3950Sstevel@tonic-gate	set_file('dir1/dirA/fileBname2', '22');
3960Sstevel@tonic-gate	set_file('dir1/dirA/fileBname3', '333');
3970Sstevel@tonic-gate	set_file('dir1/dirA/fileBname4', '4444');
3980Sstevel@tonic-gate	set_file('dir1/dirA/fileBname5', '55555');
3990Sstevel@tonic-gate	set_file('dir1/dirB/fileAname1', '1');
4000Sstevel@tonic-gate	set_file('dir1/dirB/fileAname2', '22');
4010Sstevel@tonic-gate	set_file('dir1/dirB/fileAname3', '333');
4020Sstevel@tonic-gate	set_file('dir1/dirB/fileAname4', '4444');
4030Sstevel@tonic-gate	set_file('dir1/dirB/fileAname5', '55555');
4040Sstevel@tonic-gate	set_file('dir1/dirB/fileBname1', '1');
4050Sstevel@tonic-gate	set_file('dir1/dirB/fileBname2', '22');
4060Sstevel@tonic-gate	set_file('dir1/dirB/fileBname3', '333');
4070Sstevel@tonic-gate	set_file('dir1/dirB/fileBname4', '4444');
4080Sstevel@tonic-gate	set_file('dir1/dirB/fileBname5', '55555');
4090Sstevel@tonic-gate	set_file('dir1/dirC/fileAname10', '12345678901');
4100Sstevel@tonic-gate	set_file('dir1/dirC/fileAname20', '123456789022');
4110Sstevel@tonic-gate	set_file('dir1/dirC/fileAname30', '1234567890333');
4120Sstevel@tonic-gate	set_file('dir1/dirC/fileAname40', '12345678904444');
4130Sstevel@tonic-gate	set_file('dir1/dirC/fileAname50', '123456789055555');
4140Sstevel@tonic-gate	set_file('dir1/dirC/fileBname10', '12345678901');
4150Sstevel@tonic-gate	set_file('dir1/dirC/fileBname20', '123456789022');
4160Sstevel@tonic-gate	set_file('dir1/dirC/fileBname30', '1234567890333');
4170Sstevel@tonic-gate	set_file('dir1/dirC/fileBname40', '12345678904444');
4180Sstevel@tonic-gate	set_file('dir1/dirC/fileBname50', '123456789055555');
4190Sstevel@tonic-gate
4200Sstevel@tonic-gate	set_file('std.out.expect', <<'EOF');
4210Sstevel@tonic-gate<file{A,B,C}name*>:
4220Sstevel@tonic-gate    <./fileAname12>
4230Sstevel@tonic-gate    <./fileAname1>
4240Sstevel@tonic-gate    <./fileAname3>
4250Sstevel@tonic-gate    <./fileAname5>
4260Sstevel@tonic-gate    <./fileAname7>
4270Sstevel@tonic-gate    <./fileAname9>
4280Sstevel@tonic-gate    <./fileAname11>
4290Sstevel@tonic-gate    <./fileBname12>
4300Sstevel@tonic-gate    <./fileBname0>
4310Sstevel@tonic-gate    <./fileBname2>
4320Sstevel@tonic-gate    <./fileBname4>
4330Sstevel@tonic-gate    <./fileBname6>
4340Sstevel@tonic-gate    <./fileBname8>
4350Sstevel@tonic-gate    <./fileBname10>
4360Sstevel@tonic-gatetotal size: 0
4370Sstevel@tonic-gate    oldest <./fileBname12>
4380Sstevel@tonic-gate    oldest <./fileBname8>
4390Sstevel@tonic-gate    oldest <./fileBname6>
4400Sstevel@tonic-gate    oldest <./fileBname4>
4410Sstevel@tonic-gate    oldest <./fileBname2>
4420Sstevel@tonic-gate    oldest <./fileBname10>
4430Sstevel@tonic-gate    oldest <./fileBname0>
4440Sstevel@tonic-gate    oldest <./fileAname9>
4450Sstevel@tonic-gate    oldest <./fileAname7>
4460Sstevel@tonic-gate    oldest <./fileAname5>
4470Sstevel@tonic-gate    oldest <./fileAname3>
4480Sstevel@tonic-gate    oldest <./fileAname12>
4490Sstevel@tonic-gate    oldest <./fileAname11>
4500Sstevel@tonic-gate    oldest <./fileAname1>
4510Sstevel@tonic-gate<file{A,B,C}name>:
4520Sstevel@tonic-gate    <fileAname>
4530Sstevel@tonic-gate    <fileBname>
4540Sstevel@tonic-gate    <fileCname>
4550Sstevel@tonic-gatetotal size: 0
4560Sstevel@tonic-gate    oldest <fileCname>
4570Sstevel@tonic-gate    oldest <fileBname>
4580Sstevel@tonic-gate    oldest <fileAname>
4590Sstevel@tonic-gate<dir1/dirA/file*>:
4600Sstevel@tonic-gate    <./dir1/dirA/fileAname4>
4610Sstevel@tonic-gate    <./dir1/dirA/fileAname1>
4620Sstevel@tonic-gate    <./dir1/dirA/fileAname2>
4630Sstevel@tonic-gate    <./dir1/dirA/fileAname3>
4640Sstevel@tonic-gate    <./dir1/dirA/fileAname5>
4650Sstevel@tonic-gate    <./dir1/dirA/fileBname1>
4660Sstevel@tonic-gate    <./dir1/dirA/fileBname2>
4670Sstevel@tonic-gate    <./dir1/dirA/fileBname3>
4680Sstevel@tonic-gate    <./dir1/dirA/fileBname4>
4690Sstevel@tonic-gate    <./dir1/dirA/fileBname5>
4700Sstevel@tonic-gatetotal size: 30
4710Sstevel@tonic-gate    oldest <./dir1/dirA/fileAname4>
4720Sstevel@tonic-gate    oldest <./dir1/dirA/fileBname5>
4730Sstevel@tonic-gate    oldest <./dir1/dirA/fileBname4>
4740Sstevel@tonic-gate    oldest <./dir1/dirA/fileBname3>
4750Sstevel@tonic-gate    oldest <./dir1/dirA/fileBname2>
4760Sstevel@tonic-gate    oldest <./dir1/dirA/fileBname1>
4770Sstevel@tonic-gate    oldest <./dir1/dirA/fileAname5>
4780Sstevel@tonic-gate    oldest <./dir1/dirA/fileAname3>
4790Sstevel@tonic-gate    oldest <./dir1/dirA/fileAname2>
4800Sstevel@tonic-gate    oldest <./dir1/dirA/fileAname1>
4810Sstevel@tonic-gate<dir[13]/[e-z]*>:
4820Sstevel@tonic-gate    <./dir1/fileAname1>
4830Sstevel@tonic-gate    <./dir1/fileAname2>
4840Sstevel@tonic-gate    <./dir1/fileAname3>
4850Sstevel@tonic-gate    <./dir1/fileAname4>
4860Sstevel@tonic-gate    <./dir1/fileAname5>
4870Sstevel@tonic-gate    <./dir1/fileBname1>
4880Sstevel@tonic-gate    <./dir1/fileBname2>
4890Sstevel@tonic-gate    <./dir1/fileBname3>
4900Sstevel@tonic-gate    <./dir1/fileBname4>
4910Sstevel@tonic-gate    <./dir1/fileBname5>
4920Sstevel@tonic-gatetotal size: 0
4930Sstevel@tonic-gate    oldest <./dir1/fileBname5>
4940Sstevel@tonic-gate    oldest <./dir1/fileBname4>
4950Sstevel@tonic-gate    oldest <./dir1/fileBname3>
4960Sstevel@tonic-gate    oldest <./dir1/fileBname2>
4970Sstevel@tonic-gate    oldest <./dir1/fileBname1>
4980Sstevel@tonic-gate    oldest <./dir1/fileAname5>
4990Sstevel@tonic-gate    oldest <./dir1/fileAname4>
5000Sstevel@tonic-gate    oldest <./dir1/fileAname3>
5010Sstevel@tonic-gate    oldest <./dir1/fileAname2>
5020Sstevel@tonic-gate    oldest <./dir1/fileAname1>
5030Sstevel@tonic-gate<dir?/dir[AC]/fileBname[2-9]>:
5040Sstevel@tonic-gate    <./dir1/dirA/fileBname2>
5050Sstevel@tonic-gate    <./dir1/dirA/fileBname3>
5060Sstevel@tonic-gate    <./dir1/dirA/fileBname4>
5070Sstevel@tonic-gate    <./dir1/dirA/fileBname5>
5080Sstevel@tonic-gatetotal size: 14
5090Sstevel@tonic-gate    oldest <./dir1/dirA/fileBname5>
5100Sstevel@tonic-gate    oldest <./dir1/dirA/fileBname4>
5110Sstevel@tonic-gate    oldest <./dir1/dirA/fileBname3>
5120Sstevel@tonic-gate    oldest <./dir1/dirA/fileBname2>
5130Sstevel@tonic-gate<file[A-Z]n.*e([0-9]+)$0>:
5140Sstevel@tonic-gate    <./fileBname12>
5150Sstevel@tonic-gate    <./fileAname12>
5160Sstevel@tonic-gate    <./fileAname1>
5170Sstevel@tonic-gate    <./fileAname3>
5180Sstevel@tonic-gate    <./fileAname5>
5190Sstevel@tonic-gate    <./fileAname7>
5200Sstevel@tonic-gate    <./fileAname9>
5210Sstevel@tonic-gate    <./fileAname11>
5220Sstevel@tonic-gate    <./fileBname0>
5230Sstevel@tonic-gate    <./fileBname2>
5240Sstevel@tonic-gate    <./fileBname4>
5250Sstevel@tonic-gate    <./fileBname6>
5260Sstevel@tonic-gate    <./fileBname8>
5270Sstevel@tonic-gate    <./fileBname10>
5280Sstevel@tonic-gatetotal size: 0
5290Sstevel@tonic-gate    oldest <./fileBname12>
5300Sstevel@tonic-gate    oldest <./fileAname12>
5310Sstevel@tonic-gate    oldest <./fileAname11>
5320Sstevel@tonic-gate    oldest <./fileBname10>
5330Sstevel@tonic-gate    oldest <./fileAname9>
5340Sstevel@tonic-gate    oldest <./fileBname8>
5350Sstevel@tonic-gate    oldest <./fileAname7>
5360Sstevel@tonic-gate    oldest <./fileBname6>
5370Sstevel@tonic-gate    oldest <./fileAname5>
5380Sstevel@tonic-gate    oldest <./fileBname4>
5390Sstevel@tonic-gate    oldest <./fileAname3>
5400Sstevel@tonic-gate    oldest <./fileBname2>
5410Sstevel@tonic-gate    oldest <./fileAname1>
5420Sstevel@tonic-gate    oldest <./fileBname0>
5430Sstevel@tonic-gateEOF
5440Sstevel@tonic-gate
5450Sstevel@tonic-gate	set_file('checktest', <<'EOF');
546*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
547*12986SJohn.Zolnowsky@Sun.COMexec /bin/diff std.out.expect std.out
5480Sstevel@tonic-gateEOF
5490Sstevel@tonic-gate
5500Sstevel@tonic-gate	$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\'';
5510Sstevel@tonic-gate
5520Sstevel@tonic-gate	set_file('runtest', <<"EOF");
5530Sstevel@tonic-gate# test "globtest1"
5540Sstevel@tonic-gate$envsetup
5550Sstevel@tonic-gateexec $bindir/globtest $testglobs >std.out 2>std.err
5560Sstevel@tonic-gateEOF
5570Sstevel@tonic-gate}
5580Sstevel@tonic-gate
5590Sstevel@tonic-gate###########################################################################
5600Sstevel@tonic-gate#
5610Sstevel@tonic-gate#	globtest2 -- error path through glob.c
5620Sstevel@tonic-gate#
5630Sstevel@tonic-gate###########################################################################
5640Sstevel@tonic-gatesub globtest2 {
5650Sstevel@tonic-gate	set_file('std.err.expect', <<'EOF');
5660Sstevel@tonic-gateglobtest: Error: Missing }
5670Sstevel@tonic-gateEOF
5680Sstevel@tonic-gate
5690Sstevel@tonic-gate	set_file('checktest', <<'EOF');
570*12986SJohn.Zolnowsky@Sun.COMexec /bin/diff std.err.expect std.err
5710Sstevel@tonic-gateEOF
5720Sstevel@tonic-gate
5730Sstevel@tonic-gate	set_file('runtest', <<"EOF");
5740Sstevel@tonic-gate# test "globtest2"
5750Sstevel@tonic-gate$envsetup
5760Sstevel@tonic-gate$bindir/globtest 'hello{there' >std.out 2>std.err || exit 0
5770Sstevel@tonic-gateexit 1
5780Sstevel@tonic-gateEOF
5790Sstevel@tonic-gate}
5800Sstevel@tonic-gate
5810Sstevel@tonic-gate###########################################################################
5820Sstevel@tonic-gate#
5830Sstevel@tonic-gate#	kwtest1 -- minimal basic test of the kw.c code
5840Sstevel@tonic-gate#
5850Sstevel@tonic-gate###########################################################################
5860Sstevel@tonic-gatesub kwtest1 {
5870Sstevel@tonic-gate	$domainname = `/bin/domainname`; chomp $domainname;
5880Sstevel@tonic-gate	$isa = `/bin/uname -p`; chomp $isa;
5890Sstevel@tonic-gate	$platform = `/bin/uname -i`; chomp $platform;
5900Sstevel@tonic-gate	$nodename = `/bin/uname -n`; chomp $nodename;
5910Sstevel@tonic-gate	$machine = `/bin/uname -m`; chomp $machine;
5920Sstevel@tonic-gate	$release = `/bin/uname -r`; chomp $release;
5931511Sdp	# /bin/zonename is in SUNWzoneu and so may not be present
5941511Sdp	if (-f "/bin/zonename") {
5951511Sdp		$zonename = `/bin/zonename`; chomp $zonename;
5961511Sdp	} else {
5971511Sdp		$zonename = "global";
5981511Sdp	}
5990Sstevel@tonic-gate$secondblob=<<'EOF';
6000Sstevel@tonic-gateexpand<$file.$n> n -1 hasn 1 result </var/log/syslog\.([0-9]+)$0>
6010Sstevel@tonic-gateexpand<$file.$n> n 0 hasn 1 result </var/log/syslog.0>
6020Sstevel@tonic-gateexpand<$file.$n> n 1 hasn 1 result </var/log/syslog.1>
6030Sstevel@tonic-gateexpand<moose%d.$n> n -1 hasn 1 result <moose[0-9]+\.([0-9]+)$0>
6040Sstevel@tonic-gateexpand<moose%d.$n> n 0 hasn 1 result <moose%d.0>
6050Sstevel@tonic-gateexpand<moose%d.$n> n 1 hasn 1 result <moose%d.1>
6060Sstevel@tonic-gateexpand</var/logs-%Y/moose-$isa$#porklips%d.$n> n -1 hasn 1 result </var/logs-[0-9]+/moose-ISAporklips[0-9]+\.([0-9]+)$0>
6070Sstevel@tonic-gateexpand</var/logs-%Y/moose-$isa$#porklips%d.$n> n 0 hasn 1 result </var/logs-%Y/moose-ISAporklips%d.0>
6080Sstevel@tonic-gateexpand</var/logs-%Y/moose-$isa$#porklips%d.$n> n 1 hasn 1 result </var/logs-%Y/moose-ISAporklips%d.1>
6090Sstevel@tonic-gateEOF
6100Sstevel@tonic-gate	$percentd = `/bin/env TZ=UTC /bin/date +%d`; chomp $percentd;
6110Sstevel@tonic-gate	$percentY = `/bin/env TZ=UTC /bin/date +%Y`; chomp $percentY;
6120Sstevel@tonic-gate	$secondblob =~ s/%d/$percentd/mg;
6130Sstevel@tonic-gate	$secondblob =~ s/%Y/$percentY/mg;
6140Sstevel@tonic-gate	$secondblob =~ s/ISA/$isa/mg;
615954Sgm149974	$utcenv = "TZ=UTC export TZ";
6160Sstevel@tonic-gate	chomp $secondblob;
6170Sstevel@tonic-gate	set_file('sed.out.expect', <<"EOF");
6180Sstevel@tonic-gate            basename syslog
6190Sstevel@tonic-gate             dirname /var/log
6200Sstevel@tonic-gate              domain $domainname
6210Sstevel@tonic-gate                file /var/log/syslog
6220Sstevel@tonic-gate                home $dir
6230Sstevel@tonic-gate                 isa $isa
6240Sstevel@tonic-gate             logname $ENV{LOGNAME}
6250Sstevel@tonic-gate             machine $machine
6260Sstevel@tonic-gate               nfile
6270Sstevel@tonic-gate            nodename $nodename
6280Sstevel@tonic-gate            platform $platform
6290Sstevel@tonic-gate             release $release
6300Sstevel@tonic-gate                user $ENV{USER}
6311511Sdp            zonename $zonename
6320Sstevel@tonic-gate$secondblob
6330Sstevel@tonic-gateEOF
6340Sstevel@tonic-gate
6350Sstevel@tonic-gate	set_file('checktest', <<'EOF');
636*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
6370Sstevel@tonic-gate/bin/sed -e '/^ *secs [0-9][0-9]*$/d'\
6380Sstevel@tonic-gate	-e "s/%d/`/bin/env TZ=UTC /bin/date +%d`/g"\
6390Sstevel@tonic-gate	-e "s/%Y/`/bin/env TZ=UTC /bin/date +%Y`/g"\
6400Sstevel@tonic-gate	<std.out >sed.out
641*12986SJohn.Zolnowsky@Sun.COMexec /bin/diff sed.out.expect sed.out
6420Sstevel@tonic-gateEOF
6430Sstevel@tonic-gate
6440Sstevel@tonic-gate	$kwtest='kwtest /var/log/syslog \'$file.$n\' \'moose%d.$n\' \'/var/logs-%Y/moose-$isa$#porklips%d.$n\'';
6450Sstevel@tonic-gate	set_file('runtest', <<"EOF");
6460Sstevel@tonic-gate# test "kwtest1"
6470Sstevel@tonic-gate$envsetup
648954Sgm149974$utcenv
6490Sstevel@tonic-gateexec $bindir/$kwtest >std.out 2>std.err
6500Sstevel@tonic-gateEOF
6510Sstevel@tonic-gate}
6520Sstevel@tonic-gate
6530Sstevel@tonic-gate###########################################################################
6540Sstevel@tonic-gate#
6550Sstevel@tonic-gate#	kwtest2 -- NULL environment variables test of the kw.c code
6560Sstevel@tonic-gate#
6570Sstevel@tonic-gate###########################################################################
6580Sstevel@tonic-gatesub kwtest2 {
6590Sstevel@tonic-gate	$domainname = `/bin/domainname`; chomp $domainname;
6600Sstevel@tonic-gate	$isa = `/bin/uname -p`; chomp $isa;
6610Sstevel@tonic-gate	$platform = `/bin/uname -i`; chomp $platform;
6620Sstevel@tonic-gate	$nodename = `/bin/uname -n`; chomp $nodename;
6630Sstevel@tonic-gate	$machine = `/bin/uname -m`; chomp $machine;
6640Sstevel@tonic-gate	$release = `/bin/uname -r`; chomp $release;
6651511Sdp	# /bin/zonename is in SUNWzoneu and so may not be present
6661511Sdp	if (-f "/bin/zonename") {
6671511Sdp		$zonename = `/bin/zonename`; chomp $zonename;
6681511Sdp	} else {
6691511Sdp		$zonename = "global";
6701511Sdp	}
6710Sstevel@tonic-gate$secondblob=<<'EOF';
6720Sstevel@tonic-gateexpand<$file.$n> n -1 hasn 1 result </var/log/syslog\.([0-9]+)$0>
6730Sstevel@tonic-gateexpand<$file.$n> n 0 hasn 1 result </var/log/syslog.0>
6740Sstevel@tonic-gateexpand<$file.$n> n 1 hasn 1 result </var/log/syslog.1>
6750Sstevel@tonic-gateexpand<moose%d.$n> n -1 hasn 1 result <moose[0-9]+\.([0-9]+)$0>
6760Sstevel@tonic-gateexpand<moose%d.$n> n 0 hasn 1 result <moose%d.0>
6770Sstevel@tonic-gateexpand<moose%d.$n> n 1 hasn 1 result <moose%d.1>
6780Sstevel@tonic-gateexpand</var/logs-%Y/moose-$isa$#porklips%d.$n> n -1 hasn 1 result </var/logs-[0-9]+/moose-ISAporklips[0-9]+\.([0-9]+)$0>
6790Sstevel@tonic-gateexpand</var/logs-%Y/moose-$isa$#porklips%d.$n> n 0 hasn 1 result </var/logs-%Y/moose-ISAporklips%d.0>
6800Sstevel@tonic-gateexpand</var/logs-%Y/moose-$isa$#porklips%d.$n> n 1 hasn 1 result </var/logs-%Y/moose-ISAporklips%d.1>
6810Sstevel@tonic-gateEOF
6820Sstevel@tonic-gate	$percentd = `/bin/env TZ=UTC /bin/date +%d`; chomp $percentd;
6830Sstevel@tonic-gate	$percentY = `/bin/env TZ=UTC /bin/date +%Y`; chomp $percentY;
6840Sstevel@tonic-gate	$secondblob =~ s/%d/$percentd/mg;
6850Sstevel@tonic-gate	$secondblob =~ s/%Y/$percentY/mg;
6860Sstevel@tonic-gate	$secondblob =~ s/ISA/$isa/mg;
6870Sstevel@tonic-gate	chomp $secondblob;
6880Sstevel@tonic-gate	set_file('sed.out.expect', <<"EOF");
6890Sstevel@tonic-gate            basename syslog
6900Sstevel@tonic-gate             dirname /var/log
6910Sstevel@tonic-gate              domain $domainname
6920Sstevel@tonic-gate                file /var/log/syslog
6930Sstevel@tonic-gate                home
6940Sstevel@tonic-gate                 isa $isa
6950Sstevel@tonic-gate             logname
6960Sstevel@tonic-gate             machine $machine
6970Sstevel@tonic-gate               nfile
6980Sstevel@tonic-gate            nodename $nodename
6990Sstevel@tonic-gate            platform $platform
7000Sstevel@tonic-gate             release $release
7010Sstevel@tonic-gate                user
7021511Sdp            zonename $zonename
7030Sstevel@tonic-gate$secondblob
7040Sstevel@tonic-gateEOF
7050Sstevel@tonic-gate
7060Sstevel@tonic-gate	set_file('checktest', <<'EOF');
707*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
7080Sstevel@tonic-gate/bin/sed -e '/^ *secs [0-9][0-9]*$/d'\
7090Sstevel@tonic-gate	-e "s/%d/`/bin/env TZ=UTC /bin/date +%d`/g"\
7100Sstevel@tonic-gate	-e "s/%Y/`/bin/env TZ=UTC /bin/date +%Y`/g"\
7110Sstevel@tonic-gate	<std.out >sed.out
712*12986SJohn.Zolnowsky@Sun.COMexec /bin/diff sed.out.expect sed.out
7130Sstevel@tonic-gateEOF
7140Sstevel@tonic-gate
7150Sstevel@tonic-gate	$kwtest='kwtest /var/log/syslog \'$file.$n\' \'moose%d.$n\' \'/var/logs-%Y/moose-$isa$#porklips%d.$n\'';
7160Sstevel@tonic-gate	set_file('runtest', <<"EOF");
7170Sstevel@tonic-gate# test "kwtest2"
7180Sstevel@tonic-gate$envsetup
7190Sstevel@tonic-gateLOGNAME=
7200Sstevel@tonic-gateexport LOGNAME
7210Sstevel@tonic-gateHOME=
7220Sstevel@tonic-gateexport HOME
7230Sstevel@tonic-gateUSER=
7240Sstevel@tonic-gateexport USER
725*12986SJohn.Zolnowsky@Sun.COMTZ=UTC
726*12986SJohn.Zolnowsky@Sun.COMexport TZ
7270Sstevel@tonic-gateexec $bindir/$kwtest >std.out 2>std.err
7280Sstevel@tonic-gateEOF
7290Sstevel@tonic-gate}
7300Sstevel@tonic-gate
7310Sstevel@tonic-gate###########################################################################
7320Sstevel@tonic-gate#
7330Sstevel@tonic-gate#	luttest1 -- minimal basic test of the lut.c code
7340Sstevel@tonic-gate#
7350Sstevel@tonic-gate###########################################################################
7360Sstevel@tonic-gatesub luttest1 {
7370Sstevel@tonic-gate	set_file('std.out.expect', <<'EOF');
7380Sstevel@tonic-gatelut contains:
7390Sstevel@tonic-gate<fix> <NULL> (<NULL>)
7400Sstevel@tonic-gate<one> <two> (<two>)
7410Sstevel@tonic-gate<seven> <eight> (<eight>)
7420Sstevel@tonic-gate<six> <NULL> (<NULL>)
7430Sstevel@tonic-gate<three> <four> (<four>)
7440Sstevel@tonic-gatedup lut contains:
7450Sstevel@tonic-gate<fix> <NULL> (<NULL>)
7460Sstevel@tonic-gate<one> <two> (<two>)
7470Sstevel@tonic-gate<seven> <eight> (<eight>)
7480Sstevel@tonic-gate<six> <NULL> (<NULL>)
7490Sstevel@tonic-gate<three> <four> (<four>)
7500Sstevel@tonic-gateEOF
7510Sstevel@tonic-gate
7520Sstevel@tonic-gate	set_file('checktest', <<'EOF');
753*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
754*12986SJohn.Zolnowsky@Sun.COMexec /bin/diff std.out.expect std.out
7550Sstevel@tonic-gateEOF
7560Sstevel@tonic-gate
7570Sstevel@tonic-gate	set_file('runtest', <<"EOF");
7580Sstevel@tonic-gate# test "luttest1"
7590Sstevel@tonic-gate$envsetup
7600Sstevel@tonic-gateexec $bindir/luttest one=two three=four fix six seven=eight >std.out 2>std.err
7610Sstevel@tonic-gateEOF
7620Sstevel@tonic-gate}
7630Sstevel@tonic-gate
7640Sstevel@tonic-gate###########################################################################
7650Sstevel@tonic-gate#
7660Sstevel@tonic-gate#	optstest1 -- minimal basic test of the opts.c code
7670Sstevel@tonic-gate#
7680Sstevel@tonic-gate###########################################################################
7690Sstevel@tonic-gatesub optstest1 {
7700Sstevel@tonic-gate	$options="-a -b moose -c 1h -d 'Fri Nov  2 13:19:55 2001' -e 1k -f 2 one two three";
7710Sstevel@tonic-gate	set_file('std.out.expect', <<"EOF");
7720Sstevel@tonic-gateoptions: $options
7730Sstevel@tonic-gateEOF
7740Sstevel@tonic-gate
7750Sstevel@tonic-gate	set_file('checktest', <<'EOF');
776*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
777*12986SJohn.Zolnowsky@Sun.COMexec /bin/diff std.out.expect std.out
7780Sstevel@tonic-gateEOF
7790Sstevel@tonic-gate
7800Sstevel@tonic-gate	set_file('runtest', <<"EOF");
7810Sstevel@tonic-gate# test "optstest1"
7820Sstevel@tonic-gate$envsetup
7830Sstevel@tonic-gateexec $bindir/optstest $options >std.out 2>std.err
7840Sstevel@tonic-gateEOF
7850Sstevel@tonic-gate}
7860Sstevel@tonic-gate
7870Sstevel@tonic-gate###########################################################################
7880Sstevel@tonic-gate#
7890Sstevel@tonic-gate#	optstest2 -- error path through opts.c code
7900Sstevel@tonic-gate#
7910Sstevel@tonic-gate###########################################################################
7920Sstevel@tonic-gatesub optstest2 {
7930Sstevel@tonic-gate	$options="-a -b -c 1h -d 'Fri Nov  2 13:19:55 2001' -e 1k -f 2 one two three";
7940Sstevel@tonic-gate	set_file('std.err.expect', <<'EOF');
7950Sstevel@tonic-gateoptstest: Error: Option 'b' requires an argument
7960Sstevel@tonic-gateoptstest: Error: opts parsing failed
7970Sstevel@tonic-gateEOF
7980Sstevel@tonic-gate
7990Sstevel@tonic-gate	set_file('checktest', <<'EOF');
8000Sstevel@tonic-gate[ -s std.out ] && exit 1
801*12986SJohn.Zolnowsky@Sun.COMexec /bin/diff std.err.expect std.err
8020Sstevel@tonic-gateEOF
8030Sstevel@tonic-gate
8040Sstevel@tonic-gate	set_file('runtest', <<"EOF");
8050Sstevel@tonic-gate# test "optstest2"
8060Sstevel@tonic-gate$envsetup
8070Sstevel@tonic-gate$bindir/optstest $options >std.out 2>std.err || exit 0
8080Sstevel@tonic-gateexit 1
8090Sstevel@tonic-gateEOF
8100Sstevel@tonic-gate}
8110Sstevel@tonic-gate
8120Sstevel@tonic-gate###########################################################################
8130Sstevel@tonic-gate#
8140Sstevel@tonic-gate#	logadmV1 -- test of "logadm -V"
8150Sstevel@tonic-gate#
8160Sstevel@tonic-gate###########################################################################
8170Sstevel@tonic-gatesub logadmV1 {
8180Sstevel@tonic-gate	set_testconffile;
8190Sstevel@tonic-gate
8200Sstevel@tonic-gate	set_file('std.out.expect', <<'EOF');
8210Sstevel@tonic-gate/var/adm/messages -C 4 -P 'Thu Nov  1 16:56:42 2001' -a 'kill -HUP `cat /var/run/syslog.pid`'
8220Sstevel@tonic-gate/var/cron/log -s 512k -t /var/cron/olog
8230Sstevel@tonic-gate/var/lp/logs/lpsched -C 2 -N -t '$file.$N'
8240Sstevel@tonic-gate/var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
8250Sstevel@tonic-gateapache -C 24 -a '/usr/apache/bin/apachectl graceful' -p 1m -t '/var/apache/old-logs/$basename.%Y-%m' '/var/apache/logs/*{access,error}_log'
8260Sstevel@tonic-gate/var/log/syslog -C 8 -P 'Thu Nov  1 09:16:38 2001' -a 'kill -HUP `cat /var/run/syslog.pid`'
8270Sstevel@tonic-gate/var/apache/logs/access_log -P 'Thu Nov  1 08:27:56 2001'
8280Sstevel@tonic-gate/var/apache/logs/error_log -P 'Thu Nov  1 08:27:56 2001'
8290Sstevel@tonic-gate/var/apache/logs/suexec_log -P 'Thu Nov  1 08:27:56 2001'
8300Sstevel@tonic-gate/var/apache/logs/mod_jserv.log -P 'Thu Nov  1 08:27:56 2001'
8310Sstevel@tonic-gate/var/apache/logs/jserv.log -P 'Thu Nov  1 08:27:56 2001'
8320Sstevel@tonic-gateEOF
8330Sstevel@tonic-gate
8340Sstevel@tonic-gate	set_file('checktest', <<'EOF');
835*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
836*12986SJohn.Zolnowsky@Sun.COMexec /bin/diff std.out.expect std.out
8370Sstevel@tonic-gateEOF
8380Sstevel@tonic-gate
8390Sstevel@tonic-gate	set_file('runtest', <<"EOF");
8400Sstevel@tonic-gate# test "logadmV1"
8410Sstevel@tonic-gate$envsetup
842*12986SJohn.Zolnowsky@Sun.COMexec $bindir/logadm -f testfile.conf -F testfile.conf -V >std.out 2>std.err
8430Sstevel@tonic-gateEOF
8440Sstevel@tonic-gate}
8450Sstevel@tonic-gate
8460Sstevel@tonic-gate###########################################################################
8470Sstevel@tonic-gate#
8480Sstevel@tonic-gate#	logadmV2 -- test of "logadm -V <entry>"
8490Sstevel@tonic-gate#
8500Sstevel@tonic-gate###########################################################################
8510Sstevel@tonic-gatesub logadmV2 {
8520Sstevel@tonic-gate	set_testconffile;
8530Sstevel@tonic-gate
8540Sstevel@tonic-gate	set_file('std.out.expect', <<'EOF');
8550Sstevel@tonic-gate/var/cron/log -s 512k -t /var/cron/olog
8560Sstevel@tonic-gate/var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
8570Sstevel@tonic-gateEOF
8580Sstevel@tonic-gate
8590Sstevel@tonic-gate	set_file('checktest', <<'EOF');
860*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
861*12986SJohn.Zolnowsky@Sun.COMexec /bin/diff std.out.expect std.out
8620Sstevel@tonic-gateEOF
8630Sstevel@tonic-gate
8640Sstevel@tonic-gate	set_file('runtest', <<"EOF");
8650Sstevel@tonic-gate# test "logadmV2"
8660Sstevel@tonic-gate$envsetup
867*12986SJohn.Zolnowsky@Sun.COMexec $bindir/logadm -f testfile.conf -F testfile.conf -V /var/cron/log /var/adm/pacct >std.out 2>std.err
8680Sstevel@tonic-gateEOF
8690Sstevel@tonic-gate}
8700Sstevel@tonic-gate
8710Sstevel@tonic-gate###########################################################################
8720Sstevel@tonic-gate#
8730Sstevel@tonic-gate#	logadmr -- test of "logadm -r <entry>"
8740Sstevel@tonic-gate#
8750Sstevel@tonic-gate###########################################################################
8760Sstevel@tonic-gatesub logadmr {
8770Sstevel@tonic-gate	set_testconffile;
8780Sstevel@tonic-gate	set_testconffile('testfile.conf.orig');
8790Sstevel@tonic-gate
8800Sstevel@tonic-gate	set_file('diff.out.expect', <<'EOF');
881*12986SJohn.Zolnowsky@Sun.COM18d17
882*12986SJohn.Zolnowsky@Sun.COM< /var/cron/log -s 512k -t /var/cron/olog
883*12986SJohn.Zolnowsky@Sun.COM23d21
884*12986SJohn.Zolnowsky@Sun.COM< /var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
8850Sstevel@tonic-gateEOF
8860Sstevel@tonic-gate
8870Sstevel@tonic-gate	set_file('checktest', <<'EOF');
888*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
889*12986SJohn.Zolnowsky@Sun.COM/bin/diff testfile.conf.orig testfile.conf > diff.out
890*12986SJohn.Zolnowsky@Sun.COMexec /bin/diff diff.out.expect diff.out
8910Sstevel@tonic-gateEOF
8920Sstevel@tonic-gate
8930Sstevel@tonic-gate	set_file('runtest', <<"EOF");
8940Sstevel@tonic-gate# test "logadmr"
8950Sstevel@tonic-gate$envsetup
896*12986SJohn.Zolnowsky@Sun.COMexec $bindir/logadm -f testfile.conf -F testfile.conf -r /var/cron/log /var/adm/pacct >std.out 2>std.err
8970Sstevel@tonic-gateEOF
8980Sstevel@tonic-gate}
8990Sstevel@tonic-gate
9000Sstevel@tonic-gate###########################################################################
9010Sstevel@tonic-gate#
9020Sstevel@tonic-gate#	logadmw -- test of "logadm -w <entry>"
9030Sstevel@tonic-gate#
9040Sstevel@tonic-gate###########################################################################
9050Sstevel@tonic-gatesub logadmw {
9060Sstevel@tonic-gate	set_testconffile;
9070Sstevel@tonic-gate	set_testconffile('testfile.conf.orig');
9080Sstevel@tonic-gate
9090Sstevel@tonic-gate	set_file('diff.out.expect', <<'EOF');
910*12986SJohn.Zolnowsky@Sun.COM30a31
911*12986SJohn.Zolnowsky@Sun.COM> moose -C 20 -a moose_after_cmd -g pig -m 664 -o cow -p never /moose/file
9120Sstevel@tonic-gateEOF
9130Sstevel@tonic-gate
9140Sstevel@tonic-gate	set_file('checktest', <<'EOF');
915*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
916*12986SJohn.Zolnowsky@Sun.COM/bin/diff testfile.conf.orig testfile.conf > diff.out
917*12986SJohn.Zolnowsky@Sun.COMexec /bin/diff diff.out.expect diff.out
9180Sstevel@tonic-gateEOF
9190Sstevel@tonic-gate
9200Sstevel@tonic-gate	set_file('runtest', <<"EOF");
9210Sstevel@tonic-gate# test "logadmw"
9220Sstevel@tonic-gate$envsetup
923*12986SJohn.Zolnowsky@Sun.COMexec $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
9240Sstevel@tonic-gateEOF
9250Sstevel@tonic-gate}
9260Sstevel@tonic-gate
9270Sstevel@tonic-gate###########################################################################
9280Sstevel@tonic-gate#
9290Sstevel@tonic-gate#	logadm1 -- minimal basic test of logadm rotation
9300Sstevel@tonic-gate#
9310Sstevel@tonic-gate###########################################################################
9320Sstevel@tonic-gatesub logadm1 {
9330Sstevel@tonic-gate	set_file('logfile', 'initially logfile');
9340Sstevel@tonic-gate	set_file('logfile.0', 'initially logfile.0');
9350Sstevel@tonic-gate	my ($stdev, $stino, $stmode, $stnlink, $stuid, $stgid, $strdev,
9360Sstevel@tonic-gate		$stsize, $statime, $stmtime, $stctime, $stblksize, $stblocks) =
9370Sstevel@tonic-gate		lstat 'logfile' or die "lstat logfile: $!\n";
9380Sstevel@tonic-gate
9390Sstevel@tonic-gate	set_file('checktest', <<"EOF");
940*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
9410Sstevel@tonic-gate[ -s std.out ] && exit 1
9420Sstevel@tonic-gate[ -s logfile ] && exit 1
9430Sstevel@tonic-gate[ -f logfile.0 ] || exit 1
9440Sstevel@tonic-gate[ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
9450Sstevel@tonic-gate[ "`/bin/ls -i logfile.0 | /bin/awk '{ print \$1; }'`" = "$stino" ] || exit 1
9460Sstevel@tonic-gate[ -f logfile.1 ] || exit 1
9470Sstevel@tonic-gate[ "xinitially logfile.0" = "x`/bin/cat logfile.1`" ] || exit 1
9480Sstevel@tonic-gateexit 0
9490Sstevel@tonic-gateEOF
9500Sstevel@tonic-gate
9510Sstevel@tonic-gate	set_file('runtest', <<"EOF");
9520Sstevel@tonic-gate# test "logadm1"
9530Sstevel@tonic-gate$envsetup
9540Sstevel@tonic-gateexec $bindir/logadm -f /dev/null -p now logfile >std.out 2>std.err
9550Sstevel@tonic-gateEOF
9560Sstevel@tonic-gate}
9570Sstevel@tonic-gate
9580Sstevel@tonic-gate###########################################################################
9590Sstevel@tonic-gate#
9600Sstevel@tonic-gate#	logadm1c -- same as logadm1 but with -c option
9610Sstevel@tonic-gate#
9620Sstevel@tonic-gate###########################################################################
9630Sstevel@tonic-gatesub logadm1c {
9640Sstevel@tonic-gate	set_file('logfile', 'initially logfile');
9650Sstevel@tonic-gate	set_file('logfile.0', 'initially logfile.0');
9660Sstevel@tonic-gate	my ($stdev, $stino, $stmode, $stnlink, $stuid, $stgid, $strdev,
9670Sstevel@tonic-gate		$stsize, $statime, $stmtime, $stctime, $stblksize, $stblocks) =
9680Sstevel@tonic-gate		lstat 'logfile' or die "lstat logfile: $!\n";
9690Sstevel@tonic-gate
9700Sstevel@tonic-gate	set_file('checktest', <<"EOF");
971*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
9720Sstevel@tonic-gate[ -s std.out ] && exit 1
9730Sstevel@tonic-gate[ -s logfile ] && exit 1
9740Sstevel@tonic-gate[ -f logfile.0 ] || exit 1
9750Sstevel@tonic-gate[ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
9760Sstevel@tonic-gate[ "`/bin/ls -i logfile.0 | /bin/awk '{ print \$1; }'`" = "$stino" ] && exit 1
9770Sstevel@tonic-gate[ -f logfile.1 ] || exit 1
9780Sstevel@tonic-gate[ "xinitially logfile.0" = "x`/bin/cat logfile.1`" ] || exit 1
9790Sstevel@tonic-gateexit 0
9800Sstevel@tonic-gateEOF
9810Sstevel@tonic-gate
9820Sstevel@tonic-gate	set_file('runtest', <<"EOF");
9830Sstevel@tonic-gate# test "logadm1c"
9840Sstevel@tonic-gate$envsetup
9850Sstevel@tonic-gateexec $bindir/logadm -f /dev/null -p now -c logfile >std.out 2>std.err
9860Sstevel@tonic-gateEOF
9870Sstevel@tonic-gate}
9880Sstevel@tonic-gate
9890Sstevel@tonic-gate###########################################################################
9900Sstevel@tonic-gate#
9910Sstevel@tonic-gate#	logadm2 -- minimal basic test of logadm expiration
9920Sstevel@tonic-gate#
9930Sstevel@tonic-gate###########################################################################
9940Sstevel@tonic-gatesub logadm2 {
9950Sstevel@tonic-gate	set_file('logfile', 'initially logfile');
9960Sstevel@tonic-gate	set_file('logfile.0', 'initially logfile.0');
9970Sstevel@tonic-gate	set_file('logfile.1', 'initially logfile.1');
9980Sstevel@tonic-gate
9990Sstevel@tonic-gate	set_file('checktest', <<'EOF');
1000*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
10010Sstevel@tonic-gate[ -s std.out ] && exit 1
10020Sstevel@tonic-gate[ -s logfile ] && exit 1
10030Sstevel@tonic-gate[ -f logfile.0 ] || exit 1
10040Sstevel@tonic-gate[ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
10050Sstevel@tonic-gate[ -f logfile.1 ] || exit 1
10060Sstevel@tonic-gate[ "xinitially logfile.0" = "x`/bin/cat logfile.1`" ] || exit 1
10070Sstevel@tonic-gate[ -f logfile.2 ] && exit 1
10080Sstevel@tonic-gateexit 0
10090Sstevel@tonic-gateEOF
10100Sstevel@tonic-gate
10110Sstevel@tonic-gate	set_file('runtest', <<"EOF");
10120Sstevel@tonic-gate# test "logadm2"
10130Sstevel@tonic-gate$envsetup
10140Sstevel@tonic-gateexec $bindir/logadm -f /dev/null -p now logfile -C2 >std.out 2>std.err
10150Sstevel@tonic-gateEOF
10160Sstevel@tonic-gate}
10170Sstevel@tonic-gate
10180Sstevel@tonic-gate###########################################################################
10190Sstevel@tonic-gate#
10200Sstevel@tonic-gate#	logadm3 -- minimal basic test of logadm pre/post-commands
10210Sstevel@tonic-gate#
10220Sstevel@tonic-gate###########################################################################
10230Sstevel@tonic-gatesub logadm3 {
10240Sstevel@tonic-gate	set_file('logfile', 'initially logfile');
10250Sstevel@tonic-gate	set_file('logfile.0', 'initially logfile.0');
10260Sstevel@tonic-gate	set_file('logfile.1', 'initially logfile.1');
10270Sstevel@tonic-gate
10280Sstevel@tonic-gate	set_file('checktest', <<'EOF');
1029*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
10300Sstevel@tonic-gate[ -s std.out ] && exit 1
10310Sstevel@tonic-gate[ -s logfile ] && exit 1
10320Sstevel@tonic-gate[ -f logfile.0 ] || exit 1
10330Sstevel@tonic-gate[ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
10340Sstevel@tonic-gate[ -f logfile.1 ] || exit 1
10350Sstevel@tonic-gate[ "xinitially logfile.0" = "x`/bin/cat logfile.1`" ] || exit 1
10360Sstevel@tonic-gate[ -f logfile.2 ] && exit 1
10370Sstevel@tonic-gate[ -f pre.out ] || exit 1
10380Sstevel@tonic-gate[ "xpre-command-stuff" = "x`/bin/cat pre.out`" ] || exit 1
10390Sstevel@tonic-gate[ -f post.out ] || exit 1
10400Sstevel@tonic-gate[ "xpost-command-stuff" = "x`/bin/cat post.out`" ] || exit 1
10410Sstevel@tonic-gateexit 0
10420Sstevel@tonic-gateEOF
10430Sstevel@tonic-gate
10440Sstevel@tonic-gate	set_file('runtest', <<"EOF");
10450Sstevel@tonic-gate# test "logadm3"
10460Sstevel@tonic-gate$envsetup
10470Sstevel@tonic-gateexec $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
10480Sstevel@tonic-gateEOF
10490Sstevel@tonic-gate}
10500Sstevel@tonic-gate
10510Sstevel@tonic-gate###########################################################################
10520Sstevel@tonic-gate#
10530Sstevel@tonic-gate#	logadm4 -- test of -t template
10540Sstevel@tonic-gate#
10550Sstevel@tonic-gate###########################################################################
10560Sstevel@tonic-gatesub logadm4 {
10570Sstevel@tonic-gate	set_file('logfile', 'initially logfile');
10580Sstevel@tonic-gate
10590Sstevel@tonic-gate	set_file('checktest', <<'EOF');
1060*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
10610Sstevel@tonic-gate[ -s std.out ] && exit 1
10620Sstevel@tonic-gate[ -s logfile ] && exit 1
10630Sstevel@tonic-gateTZ=UTC export TZ
10640Sstevel@tonic-gated=`/bin/date +%d`
10650Sstevel@tonic-gate[ -f logfile.$d ] || exit 1
10660Sstevel@tonic-gate[ "xinitially logfile" = "x`/bin/cat logfile.$d`" ] || exit 1
10670Sstevel@tonic-gateexit 0
10680Sstevel@tonic-gateEOF
10690Sstevel@tonic-gate
10700Sstevel@tonic-gate	set_file('runtest', <<"EOF");
10710Sstevel@tonic-gate# test "logadm4"
10720Sstevel@tonic-gate$envsetup
10730Sstevel@tonic-gateexec $bindir/logadm -f /dev/null -p now logfile -t '\$file.\%d' >std.out 2>std.err
10740Sstevel@tonic-gateEOF
10750Sstevel@tonic-gate}
10760Sstevel@tonic-gate
10770Sstevel@tonic-gate###########################################################################
10780Sstevel@tonic-gate#
10790Sstevel@tonic-gate#	logadm5 -- test of -R cmd and -E cmd
10800Sstevel@tonic-gate#
10810Sstevel@tonic-gate###########################################################################
10820Sstevel@tonic-gatesub logadm5 {
10830Sstevel@tonic-gate	set_file('logfile', 'initially logfile');
10840Sstevel@tonic-gate	set_file('logfile.0', 'initially logfile.0');
10850Sstevel@tonic-gate
10860Sstevel@tonic-gate	set_file('cmd.out.expect', <<'EOF');
10870Sstevel@tonic-gatejust rotated: initially logfile
10880Sstevel@tonic-gatejust expired: initially logfile.0
10890Sstevel@tonic-gateEOF
10900Sstevel@tonic-gate
10910Sstevel@tonic-gate	set_file('checktest', <<'EOF');
1092*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
10930Sstevel@tonic-gate[ -s std.out ] && exit 1
10940Sstevel@tonic-gate[ -s logfile ] && exit 1
10950Sstevel@tonic-gate[ -f logfile.0 ] || exit 1
10960Sstevel@tonic-gate[ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
10970Sstevel@tonic-gate[ -f logfile.1 ] || exit 1
10980Sstevel@tonic-gate[ "xinitially logfile.0" = "x`/bin/cat logfile.1`" ] || exit 1
1099*12986SJohn.Zolnowsky@Sun.COMexec /bin/diff cmd.out.expect cmd.out
11000Sstevel@tonic-gateEOF
11010Sstevel@tonic-gate
11020Sstevel@tonic-gate	set_file('runtest', <<"EOF");
11030Sstevel@tonic-gate# test "logadm5"
11040Sstevel@tonic-gate$envsetup
11050Sstevel@tonic-gateexec $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
11060Sstevel@tonic-gateEOF
11070Sstevel@tonic-gate}
11080Sstevel@tonic-gate
11090Sstevel@tonic-gate###########################################################################
11100Sstevel@tonic-gate#
11110Sstevel@tonic-gate#	logadm6 -- test of -m, -o, -g
11120Sstevel@tonic-gate#
11130Sstevel@tonic-gate###########################################################################
11140Sstevel@tonic-gatesub logadm6 {
11150Sstevel@tonic-gate        set_file('logfile', 'initially logfile');
11160Sstevel@tonic-gate
11170Sstevel@tonic-gate        set_file('std.err.expect', <<'EOF');
11180Sstevel@tonic-gatelogadm: Warning: command failed: /bin/chown _nonexistentuser_:_nonexistentgroup_ logfile
11190Sstevel@tonic-gatechown: unknown group id _nonexistentgroup_
11200Sstevel@tonic-gateEOF
11210Sstevel@tonic-gate
11220Sstevel@tonic-gate        set_file('checktest', <<'EOF');
1123*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] || exit 1;
11240Sstevel@tonic-gate[ -s std.out ] && exit 1
11250Sstevel@tonic-gate[ -s logfile ] && exit 1
11260Sstevel@tonic-gate[ -f logfile.0 ] || exit 1
11270Sstevel@tonic-gate[ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
11280Sstevel@tonic-gate[ "`/bin/ls -l logfile | /bin/awk '{ print $1; }'`" = "-r----x--x" ] || exit 1
1129*12986SJohn.Zolnowsky@Sun.COMexec /bin/diff std.err.expect std.err
11300Sstevel@tonic-gateEOF
11310Sstevel@tonic-gate
11320Sstevel@tonic-gate        set_file('runtest', <<"EOF");
11330Sstevel@tonic-gate# test "logadm6"
11340Sstevel@tonic-gate$envsetup
11350Sstevel@tonic-gateexec $bindir/logadm -f /dev/null -p now logfile -m 411 -o _nonexistentuser_ -g _nonexistentgroup_ >std.out 2>std.err
11360Sstevel@tonic-gateEOF
11370Sstevel@tonic-gate}
11380Sstevel@tonic-gate
11390Sstevel@tonic-gate###########################################################################
11400Sstevel@tonic-gate#
11410Sstevel@tonic-gate#       logadm7 -- test running through a conffile
11420Sstevel@tonic-gate#
11430Sstevel@tonic-gate###########################################################################
11440Sstevel@tonic-gatesub logadm7 {
11450Sstevel@tonic-gate	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
11460Sstevel@tonic-gate	set_file('dir1/syslog', 'initially dir1/syslog');
11470Sstevel@tonic-gate	set_file('dir1/syslog.0', 'initially dir1/syslog.0');
11480Sstevel@tonic-gate	set_file('dir1/syslog.1', 'initially dir1/syslog.1');
11490Sstevel@tonic-gate	set_file('dir1/syslog.2', 'initially dir1/syslog.2');
11500Sstevel@tonic-gate	set_file('dir1/syslog.3', 'initially dir1/syslog.3');
11510Sstevel@tonic-gate	set_file('dir1/syslog.4', 'initially dir1/syslog.4');
11520Sstevel@tonic-gate	set_file('dir1/syslog.5', 'initially dir1/syslog.5');
11530Sstevel@tonic-gate	set_file('dir1/syslog.6', 'initially dir1/syslog.6');
11540Sstevel@tonic-gate	set_file('dir1/syslog.7', 'initially dir1/syslog.7');
11550Sstevel@tonic-gate	mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
11560Sstevel@tonic-gate	set_file('dir2/messages', 'initially dir2/messages');
11570Sstevel@tonic-gate	set_file('dir2/messages.0', 'initially dir2/messages.0');
11580Sstevel@tonic-gate	set_file('dir2/messages.1', 'initially dir2/messages.1');
11590Sstevel@tonic-gate	set_file('dir2/messages.2', 'initially dir2/messages.2');
11600Sstevel@tonic-gate	set_file('dir2/messages.3', 'initially dir2/messages.3');
11610Sstevel@tonic-gate
11620Sstevel@tonic-gate	set_file('logadm.conf', <<'EOF');
11630Sstevel@tonic-gate#
11640Sstevel@tonic-gate# logadm.conf
11650Sstevel@tonic-gate#
11660Sstevel@tonic-gate#	this comment # has at least another #-sign in it #...
11670Sstevel@tonic-gate#
11680Sstevel@tonic-gate# Default settings for system log file management.
11690Sstevel@tonic-gate# The -w option to logadm(1M) is the preferred way to write to this file,
11700Sstevel@tonic-gate# but if you do edit it by hand, use "logadm -V" to check it for errors.
11710Sstevel@tonic-gate# but if you do edit it by hand, use "logadm -V" to check it for errors.
11720Sstevel@tonic-gate#
11730Sstevel@tonic-gate# The format of lines in this file is:
11740Sstevel@tonic-gate#       <logname> <options>
11750Sstevel@tonic-gate# For each logname listed here, the default options to logadm
11760Sstevel@tonic-gate# are given.  Options given on the logadm command line override
11770Sstevel@tonic-gate# the defaults contained in this file.
11780Sstevel@tonic-gate#
11790Sstevel@tonic-gate# logadm typically runs early every morning via an entry in
11800Sstevel@tonic-gate# root's crontab (see crontab(1)).
11810Sstevel@tonic-gate#
11820Sstevel@tonic-gatedir1/syslog -C 8 -a 'echo kill -HUP `cat /etc/syslog.pid` >> cmd.out'
11830Sstevel@tonic-gatedir2/messages -C 4 -a 'echo kill -HUP `cat /etc/syslog.pid` >> cmd.out'
11840Sstevel@tonic-gate#
11850Sstevel@tonic-gate# The entry below is used by turnacct(1M)
11860Sstevel@tonic-gate#
11870Sstevel@tonic-gate/var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
11880Sstevel@tonic-gateEOF
11890Sstevel@tonic-gate
11900Sstevel@tonic-gate	system("/bin/cp logadm.conf logadm.conf.orig");
11910Sstevel@tonic-gate
11920Sstevel@tonic-gate	$pid=`cat /etc/syslog.pid`;
11930Sstevel@tonic-gate	chomp $pid;
11940Sstevel@tonic-gate	set_file('cmd.out.expect', <<"EOF");
11950Sstevel@tonic-gatekill -HUP $pid
11960Sstevel@tonic-gatesecond kill -HUP $pid
11970Sstevel@tonic-gateEOF
11980Sstevel@tonic-gate
1199*12986SJohn.Zolnowsky@Sun.COM	set_file('sed.out.expect', <<'EOF');
1200*12986SJohn.Zolnowsky@Sun.COM# This file holds internal data for logadm(1M).
1201*12986SJohn.Zolnowsky@Sun.COM# Do not edit.
1202*12986SJohn.Zolnowsky@Sun.COMdir1/syslog
1203*12986SJohn.Zolnowsky@Sun.COMdir2/messages
1204*12986SJohn.Zolnowsky@Sun.COMEOF
1205*12986SJohn.Zolnowsky@Sun.COM
12060Sstevel@tonic-gate	set_file('checktest', <<'EOF');
1207*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
12080Sstevel@tonic-gate[ -s std.out ] && exit 1
1209*12986SJohn.Zolnowsky@Sun.COM[ -s logadm.timestamps ] || exit 1
12100Sstevel@tonic-gate[ -s std.err2 ] && exit 1
12110Sstevel@tonic-gate[ -s std.out2 ] && exit 1
12120Sstevel@tonic-gate[ -s std.err3 ] && exit 1
12130Sstevel@tonic-gate[ -s std.out3 ] && exit 1
12140Sstevel@tonic-gate[ -s std.err4 ] && exit 1
12150Sstevel@tonic-gate[ -s std.out4 ] && exit 1
12160Sstevel@tonic-gate[ -f dir1/syslog ] || exit 1
12170Sstevel@tonic-gate[ "xsomething" = "x`/bin/cat dir1/syslog`" ] || exit 1
12180Sstevel@tonic-gate[ -f dir1/syslog.0 ] || exit 1
12190Sstevel@tonic-gate[ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
12200Sstevel@tonic-gate[ -f dir1/syslog.1 ] || exit 1
12210Sstevel@tonic-gate[ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
12220Sstevel@tonic-gate[ -f dir1/syslog.2 ] || exit 1
12230Sstevel@tonic-gate[ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
12240Sstevel@tonic-gate[ -f dir1/syslog.3 ] || exit 1
12250Sstevel@tonic-gate[ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
12260Sstevel@tonic-gate[ -f dir1/syslog.4 ] || exit 1
12270Sstevel@tonic-gate[ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
12280Sstevel@tonic-gate[ -f dir1/syslog.5 ] || exit 1
12290Sstevel@tonic-gate[ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
12300Sstevel@tonic-gate[ -f dir1/syslog.6 ] || exit 1
12310Sstevel@tonic-gate[ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
12320Sstevel@tonic-gate[ -f dir1/syslog.7 ] || exit 1
12330Sstevel@tonic-gate[ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
12340Sstevel@tonic-gate[ -f dir1/syslog.8 ] && exit 1
12350Sstevel@tonic-gate
12360Sstevel@tonic-gate[ -s dir2/messages ] && exit 1
12370Sstevel@tonic-gate[ -f dir2/messages.0 ] || exit 1
12380Sstevel@tonic-gate[ "xsomething" = "x`/bin/cat dir2/messages.0`" ] || exit 1
12390Sstevel@tonic-gate[ -f dir2/messages.1 ] || exit 1
12400Sstevel@tonic-gate[ "xinitially dir2/messages" = "x`/bin/cat dir2/messages.1`" ] || exit 1
12410Sstevel@tonic-gate[ -f dir2/messages.2 ] || exit 1
12420Sstevel@tonic-gate[ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.2`" ] || exit 1
12430Sstevel@tonic-gate[ -f dir2/messages.3 ] || exit 1
12440Sstevel@tonic-gate[ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.3`" ] || exit 1
12450Sstevel@tonic-gate[ -f dir2/messages.4 ] && exit 1
1246*12986SJohn.Zolnowsky@Sun.COM/bin/sed "s/ -P '[^']*' *//" < logadm.timestamps > sed.out
1247*12986SJohn.Zolnowsky@Sun.COM/bin/diff sed.out.expect sed.out || exit 1
1248*12986SJohn.Zolnowsky@Sun.COMexec /bin/diff logadm.conf.orig logadm.conf
12490Sstevel@tonic-gateEOF
12500Sstevel@tonic-gate
12510Sstevel@tonic-gate        # first logadm call will rotate both syslog and messages
12520Sstevel@tonic-gate        # second one won't because size is zero
12530Sstevel@tonic-gate        # third one won't because of -P timestamps stored in conffile
12540Sstevel@tonic-gate        # fourth one will do messages because of -p now on command line
12550Sstevel@tonic-gate        set_file('runtest', <<"EOF");
12560Sstevel@tonic-gate# test "logadm7"
12570Sstevel@tonic-gate$envsetup
1258*12986SJohn.Zolnowsky@Sun.COM$bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err || exit 1
1259*12986SJohn.Zolnowsky@Sun.COM$bindir/logadm -f logadm.conf -F logadm.timestamps dir1/syslog dir2/messages >std.out2 2>std.err2 || exit 1
12600Sstevel@tonic-gateecho something > dir1/syslog
12610Sstevel@tonic-gateecho something > dir2/messages
1262*12986SJohn.Zolnowsky@Sun.COM$bindir/logadm -f logadm.conf -F logadm.timestamps >std.out3 2>std.err3 || exit 1
1263*12986SJohn.Zolnowsky@Sun.COMexec $bindir/logadm -f logadm.conf -F logadm.timestamps dir2/messages -p now -a 'echo second kill -HUP `cat /etc/syslog.pid` >> cmd.out' >std.out4 2>std.err4
12640Sstevel@tonic-gateEOF
12650Sstevel@tonic-gate}
12660Sstevel@tonic-gate
12670Sstevel@tonic-gate###########################################################################
12680Sstevel@tonic-gate#
12690Sstevel@tonic-gate#       logadm8 -- test of -z
12700Sstevel@tonic-gate#
12710Sstevel@tonic-gate###########################################################################
12720Sstevel@tonic-gatesub logadm8 {
12730Sstevel@tonic-gate	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
12740Sstevel@tonic-gate	set_file('dir1/syslog', 'initially dir1/syslog');
12750Sstevel@tonic-gate	set_file('dir1/syslog.0', 'initially dir1/syslog.0');
12760Sstevel@tonic-gate	set_file('dir1/syslog.1', 'initially dir1/syslog.1');
12770Sstevel@tonic-gate	set_file('dir1/syslog.2', 'initially dir1/syslog.2');
12780Sstevel@tonic-gate	system("/bin/gzip dir1/syslog.2");
12790Sstevel@tonic-gate	die "gzip dir1/syslog.2 didn't work\n" unless -f 'dir1/syslog.2.gz';
12800Sstevel@tonic-gate	set_file('dir1/syslog.3', 'initially dir1/syslog.3');
12810Sstevel@tonic-gate	system("/bin/gzip dir1/syslog.3");
12820Sstevel@tonic-gate	die "gzip dir1/syslog.3 didn't work\n" unless -f 'dir1/syslog.3.gz';
12830Sstevel@tonic-gate	set_file('dir1/syslog.4', 'initially dir1/syslog.4');
12840Sstevel@tonic-gate	system("/bin/gzip dir1/syslog.4");
12850Sstevel@tonic-gate	die "gzip dir1/syslog.4 didn't work\n" unless -f 'dir1/syslog.4.gz';
12860Sstevel@tonic-gate	set_file('dir1/syslog.5', 'initially dir1/syslog.5');
12870Sstevel@tonic-gate	system("/bin/gzip dir1/syslog.5");
12880Sstevel@tonic-gate	die "gzip dir1/syslog.5 didn't work\n" unless -f 'dir1/syslog.5.gz';
12890Sstevel@tonic-gate	set_file('dir1/syslog.6', 'initially dir1/syslog.6');
12900Sstevel@tonic-gate	system("/bin/gzip dir1/syslog.6");
12910Sstevel@tonic-gate	die "gzip dir1/syslog.6 didn't work\n" unless -f 'dir1/syslog.6.gz';
12920Sstevel@tonic-gate	set_file('dir1/syslog.7', 'initially dir1/syslog.7');
12930Sstevel@tonic-gate	system("/bin/gzip dir1/syslog.7");
12940Sstevel@tonic-gate	die "gzip dir1/syslog.7 didn't work\n" unless -f 'dir1/syslog.7.gz';
12950Sstevel@tonic-gate
12960Sstevel@tonic-gate	set_file('checktest', <<'EOF');
1297*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
12980Sstevel@tonic-gate[ -s std.out ] && exit 1
12990Sstevel@tonic-gate[ -f dir1/syslog ] || exit 1
13000Sstevel@tonic-gate[ -s dir1/syslog ] && exit 1
13010Sstevel@tonic-gate[ -f dir1/syslog.0 ] || exit 1
13020Sstevel@tonic-gate[ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
13030Sstevel@tonic-gate[ -f dir1/syslog.1 ] || exit 1
13040Sstevel@tonic-gate[ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
13050Sstevel@tonic-gate[ -f dir1/syslog.2.gz ] || exit 1
13060Sstevel@tonic-gate[ "xinitially dir1/syslog.1" = "x`/bin/gzcat dir1/syslog.2.gz`" ] || exit 1
13070Sstevel@tonic-gate[ -f dir1/syslog.3.gz ] || exit 1
13080Sstevel@tonic-gate[ "xinitially dir1/syslog.2" = "x`/bin/gzcat dir1/syslog.3.gz`" ] || exit 1
13090Sstevel@tonic-gate[ -f dir1/syslog.4.gz ] || exit 1
13100Sstevel@tonic-gate[ "xinitially dir1/syslog.3" = "x`/bin/gzcat dir1/syslog.4.gz`" ] || exit 1
13110Sstevel@tonic-gate[ -f dir1/syslog.5.gz ] || exit 1
13120Sstevel@tonic-gate[ "xinitially dir1/syslog.4" = "x`/bin/gzcat dir1/syslog.5.gz`" ] || exit 1
13130Sstevel@tonic-gate[ -f dir1/syslog.6.gz ] || exit 1
13140Sstevel@tonic-gate[ "xinitially dir1/syslog.5" = "x`/bin/gzcat dir1/syslog.6.gz`" ] || exit 1
13150Sstevel@tonic-gate[ -f dir1/syslog.7.gz ] || exit 1
13160Sstevel@tonic-gate[ "xinitially dir1/syslog.6" = "x`/bin/gzcat dir1/syslog.7.gz`" ] || exit 1
13170Sstevel@tonic-gate[ -f dir1/syslog.8 ] && exit 1
13180Sstevel@tonic-gate[ -f dir1/syslog.8.gz ] && exit 1
13190Sstevel@tonic-gateexit 0
13200Sstevel@tonic-gateEOF
13210Sstevel@tonic-gate
13220Sstevel@tonic-gate        set_file('runtest', <<"EOF");
13230Sstevel@tonic-gate# test "logadm8"
13240Sstevel@tonic-gate$envsetup
13250Sstevel@tonic-gateexec $bindir/logadm -f /dev/null dir1/syslog -z 2 -C 8 >std.out 2>std.err
13260Sstevel@tonic-gateEOF
13270Sstevel@tonic-gate}
13280Sstevel@tonic-gate
13290Sstevel@tonic-gate###########################################################################
13300Sstevel@tonic-gate#
13310Sstevel@tonic-gate#       logadm9 -- test of age check
13320Sstevel@tonic-gate#
13330Sstevel@tonic-gate###########################################################################
13340Sstevel@tonic-gatesub logadm9 {
13350Sstevel@tonic-gate	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
13360Sstevel@tonic-gate	set_file('dir1/syslog', 'initially dir1/syslog');
13370Sstevel@tonic-gate	set_file('dir1/syslog.0', 'initially dir1/syslog.0');
13380Sstevel@tonic-gate	set_file('dir1/syslog.1', 'initially dir1/syslog.1');
13390Sstevel@tonic-gate	set_file('dir1/syslog.2', 'initially dir1/syslog.2');
13400Sstevel@tonic-gate	set_file('dir1/syslog.3', 'initially dir1/syslog.3');
13410Sstevel@tonic-gate	set_file('dir1/syslog.4', 'initially dir1/syslog.4');
13420Sstevel@tonic-gate	set_file('dir1/syslog.5', 'initially dir1/syslog.5');
13430Sstevel@tonic-gate	set_file('dir1/syslog.6', 'initially dir1/syslog.6');
13440Sstevel@tonic-gate	set_file('dir1/syslog.7', 'initially dir1/syslog.7');
1345*12986SJohn.Zolnowsky@Sun.COM	set_file('dir1/notes', 'initially dir1/notes');
13460Sstevel@tonic-gate	mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
13470Sstevel@tonic-gate	set_file('dir2/messages', 'initially dir2/messages');
13480Sstevel@tonic-gate	set_file('dir2/messages.0', 'initially dir2/messages.0');
13490Sstevel@tonic-gate	set_file('dir2/messages.1', 'initially dir2/messages.1');
13500Sstevel@tonic-gate	set_file('dir2/messages.2', 'initially dir2/messages.2');
13510Sstevel@tonic-gate	set_file('dir2/messages.3', 'initially dir2/messages.3');
1352*12986SJohn.Zolnowsky@Sun.COM	set_file('dir2/log', 'initially dir2/log');
13530Sstevel@tonic-gate
13540Sstevel@tonic-gate	$now = time;
13550Sstevel@tonic-gate	$nowstr = gmtime($now);
13560Sstevel@tonic-gate	# a week minus 30 seconds ago...
13570Sstevel@tonic-gate	# technically not a full week, but the heuristic used by logadm
13580Sstevel@tonic-gate	# should think this is "close enough" to a full week
13590Sstevel@tonic-gate	$closetoweeksecs = $now - (60 * 60 * 24 * 7 - 30);
13600Sstevel@tonic-gate	$closetoweek = gmtime($closetoweeksecs);
13610Sstevel@tonic-gate	# a week minus six hours ago...
13620Sstevel@tonic-gate	$lessthanweeksecs = $now - (60 * 60 * 24 * 7 - 60 * 60 * 6);
13630Sstevel@tonic-gate	$lessthanweek = gmtime($lessthanweeksecs);
13640Sstevel@tonic-gate
13650Sstevel@tonic-gate	set_file('logadm.conf', <<"EOF");
13660Sstevel@tonic-gate# now: $nowstr is $now
13670Sstevel@tonic-gate# $closetoweek is $closetoweeksecs
13680Sstevel@tonic-gatedir1/syslog -C 8 -P '$closetoweek'
1369*12986SJohn.Zolnowsky@Sun.COMdir2/log -C 4
13700Sstevel@tonic-gate# $lessthanweek is $lessthanweeksecs
1371*12986SJohn.Zolnowsky@Sun.COMdir1/notes -C 2 -P '$lessthanweek'
1372*12986SJohn.Zolnowsky@Sun.COMdir2/messages -C 4
1373*12986SJohn.Zolnowsky@Sun.COMEOF
1374*12986SJohn.Zolnowsky@Sun.COM	set_file('logadm.timestamps', <<"EOF");
1375*12986SJohn.Zolnowsky@Sun.COMdir2/log -P '$closetoweek'
1376*12986SJohn.Zolnowsky@Sun.COMdir2/messages -P '$lessthanweek'
1377*12986SJohn.Zolnowsky@Sun.COMEOF
1378*12986SJohn.Zolnowsky@Sun.COM
1379*12986SJohn.Zolnowsky@Sun.COM	set_file('sed.out.expect', <<"EOF");
1380*12986SJohn.Zolnowsky@Sun.COM# This file holds internal data for logadm(1M).
1381*12986SJohn.Zolnowsky@Sun.COM# Do not edit.
1382*12986SJohn.Zolnowsky@Sun.COMdir1/syslog
1383*12986SJohn.Zolnowsky@Sun.COMdir2/log
1384*12986SJohn.Zolnowsky@Sun.COMdir1/notes
1385*12986SJohn.Zolnowsky@Sun.COMdir2/messages
13860Sstevel@tonic-gateEOF
13870Sstevel@tonic-gate
13880Sstevel@tonic-gate	set_file('checktest', <<'EOF');
1389*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
13900Sstevel@tonic-gate[ -s std.out ] && exit 1
13910Sstevel@tonic-gate[ -f dir1/syslog ] || exit 1
13920Sstevel@tonic-gate[ -s dir1/syslog ] && exit 1
13930Sstevel@tonic-gate[ -f dir1/syslog.0 ] || exit 1
13940Sstevel@tonic-gate[ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
13950Sstevel@tonic-gate[ -f dir1/syslog.1 ] || exit 1
13960Sstevel@tonic-gate[ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
13970Sstevel@tonic-gate[ -f dir1/syslog.2 ] || exit 1
13980Sstevel@tonic-gate[ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
13990Sstevel@tonic-gate[ -f dir1/syslog.3 ] || exit 1
14000Sstevel@tonic-gate[ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
14010Sstevel@tonic-gate[ -f dir1/syslog.4 ] || exit 1
14020Sstevel@tonic-gate[ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
14030Sstevel@tonic-gate[ -f dir1/syslog.5 ] || exit 1
14040Sstevel@tonic-gate[ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
14050Sstevel@tonic-gate[ -f dir1/syslog.6 ] || exit 1
14060Sstevel@tonic-gate[ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
14070Sstevel@tonic-gate[ -f dir1/syslog.7 ] || exit 1
14080Sstevel@tonic-gate[ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
14090Sstevel@tonic-gate[ -f dir1/syslog.8 ] && exit 1
14100Sstevel@tonic-gate
1411*12986SJohn.Zolnowsky@Sun.COM[ -s dir1/notes ] || exit 1
1412*12986SJohn.Zolnowsky@Sun.COM[ "xinitially dir1/notes" = "x`/bin/cat dir1/notes`" ] || exit 1
1413*12986SJohn.Zolnowsky@Sun.COM[ -f dir1/notes.0 ] && exit 1
1414*12986SJohn.Zolnowsky@Sun.COM
14150Sstevel@tonic-gate[ -f dir2/messages ] || exit 1
14160Sstevel@tonic-gate[ "xinitially dir2/messages" = "x`/bin/cat dir2/messages`" ] || exit 1
14170Sstevel@tonic-gate[ -f dir2/messages.0 ] || exit 1
14180Sstevel@tonic-gate[ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.0`" ] || exit 1
14190Sstevel@tonic-gate[ -f dir2/messages.1 ] || exit 1
14200Sstevel@tonic-gate[ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.1`" ] || exit 1
14210Sstevel@tonic-gate[ -f dir2/messages.2 ] || exit 1
14220Sstevel@tonic-gate[ "xinitially dir2/messages.2" = "x`/bin/cat dir2/messages.2`" ] || exit 1
14230Sstevel@tonic-gate[ -f dir2/messages.3 ] || exit 1
14240Sstevel@tonic-gate[ "xinitially dir2/messages.3" = "x`/bin/cat dir2/messages.3`" ] || exit 1
14250Sstevel@tonic-gate[ -f dir2/messages.4 ] && exit 1
1426*12986SJohn.Zolnowsky@Sun.COM
1427*12986SJohn.Zolnowsky@Sun.COM[ -f dir2/log ] || exit 1
1428*12986SJohn.Zolnowsky@Sun.COM[ -s dir2/log ] && exit 1
1429*12986SJohn.Zolnowsky@Sun.COM[ -f dir2/log.0 ] || exit 1
1430*12986SJohn.Zolnowsky@Sun.COM[ "xinitially dir2/log" = "x`/bin/cat dir2/log.0`" ] || exit 1
1431*12986SJohn.Zolnowsky@Sun.COM[ -f dir2/log.1 ] && exit 1
1432*12986SJohn.Zolnowsky@Sun.COM
1433*12986SJohn.Zolnowsky@Sun.COM/bin/sed "s/ -P '[^']*' *//" < logadm.timestamps > sed.out
1434*12986SJohn.Zolnowsky@Sun.COM/bin/diff sed.out.expect sed.out || exit 1
1435*12986SJohn.Zolnowsky@Sun.COM/bin/sed -n "s/ -P '[^']*' */<&>/p" < logadm.conf > sed.out
1436*12986SJohn.Zolnowsky@Sun.COM[ -s sed.out ] && exit 1
14370Sstevel@tonic-gateexit 0
14380Sstevel@tonic-gateEOF
14390Sstevel@tonic-gate
14400Sstevel@tonic-gate        set_file('runtest', <<"EOF");
14410Sstevel@tonic-gate# test "logadm9"
14420Sstevel@tonic-gate$envsetup
1443*12986SJohn.Zolnowsky@Sun.COMexec $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err
14440Sstevel@tonic-gateEOF
14450Sstevel@tonic-gate}
14460Sstevel@tonic-gate
14470Sstevel@tonic-gate###########################################################################
14480Sstevel@tonic-gate#
14490Sstevel@tonic-gate#       logadm9d -- test of age check like logadm9, but age is a couple days
14500Sstevel@tonic-gate#
14510Sstevel@tonic-gate###########################################################################
14520Sstevel@tonic-gatesub logadm9d {
14530Sstevel@tonic-gate	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
14540Sstevel@tonic-gate	set_file('dir1/syslog', 'initially dir1/syslog');
14550Sstevel@tonic-gate	set_file('dir1/syslog.0', 'initially dir1/syslog.0');
14560Sstevel@tonic-gate	set_file('dir1/syslog.1', 'initially dir1/syslog.1');
14570Sstevel@tonic-gate	set_file('dir1/syslog.2', 'initially dir1/syslog.2');
14580Sstevel@tonic-gate	set_file('dir1/syslog.3', 'initially dir1/syslog.3');
14590Sstevel@tonic-gate	set_file('dir1/syslog.4', 'initially dir1/syslog.4');
14600Sstevel@tonic-gate	set_file('dir1/syslog.5', 'initially dir1/syslog.5');
14610Sstevel@tonic-gate	set_file('dir1/syslog.6', 'initially dir1/syslog.6');
14620Sstevel@tonic-gate	set_file('dir1/syslog.7', 'initially dir1/syslog.7');
14630Sstevel@tonic-gate	mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
14640Sstevel@tonic-gate	set_file('dir2/messages', 'initially dir2/messages');
14650Sstevel@tonic-gate	set_file('dir2/messages.0', 'initially dir2/messages.0');
14660Sstevel@tonic-gate	set_file('dir2/messages.1', 'initially dir2/messages.1');
14670Sstevel@tonic-gate	set_file('dir2/messages.2', 'initially dir2/messages.2');
14680Sstevel@tonic-gate	set_file('dir2/messages.3', 'initially dir2/messages.3');
14690Sstevel@tonic-gate
14700Sstevel@tonic-gate	$now = time;
14710Sstevel@tonic-gate	$nowstr = gmtime($now);
14720Sstevel@tonic-gate	# a day minus 30 seconds ago...
14730Sstevel@tonic-gate	$closetodaysecs = $now - (60 * 60 * 24 - 30);
14740Sstevel@tonic-gate	$closetoday = gmtime($closetodaysecs);
14750Sstevel@tonic-gate	# a day minus six hours ago...
14760Sstevel@tonic-gate	$lessthandaysecs = $now - (60 * 60 * 24 - 60 * 60 * 6);
14770Sstevel@tonic-gate	$lessthanday = gmtime($lessthandaysecs);
14780Sstevel@tonic-gate
14790Sstevel@tonic-gate	set_file('logadm.conf', <<"EOF");
14800Sstevel@tonic-gate# now: $nowstr is $now
14810Sstevel@tonic-gate# $closetoday is $closetodaysecs
14820Sstevel@tonic-gatedir1/syslog -p 1d -C 8 -P '$closetoday'
14830Sstevel@tonic-gate# $lessthanday is $lessthandaysecs
14840Sstevel@tonic-gatedir2/messages -p 1d -C 4 -P '$lessthanday'
14850Sstevel@tonic-gateEOF
14860Sstevel@tonic-gate
14870Sstevel@tonic-gate	set_file('checktest', <<'EOF');
1488*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
14890Sstevel@tonic-gate[ -s std.out ] && exit 1
14900Sstevel@tonic-gate[ -f dir1/syslog ] || exit 1
14910Sstevel@tonic-gate[ -s dir1/syslog ] && exit 1
14920Sstevel@tonic-gate[ -f dir1/syslog.0 ] || exit 1
14930Sstevel@tonic-gate[ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
14940Sstevel@tonic-gate[ -f dir1/syslog.1 ] || exit 1
14950Sstevel@tonic-gate[ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
14960Sstevel@tonic-gate[ -f dir1/syslog.2 ] || exit 1
14970Sstevel@tonic-gate[ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
14980Sstevel@tonic-gate[ -f dir1/syslog.3 ] || exit 1
14990Sstevel@tonic-gate[ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
15000Sstevel@tonic-gate[ -f dir1/syslog.4 ] || exit 1
15010Sstevel@tonic-gate[ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
15020Sstevel@tonic-gate[ -f dir1/syslog.5 ] || exit 1
15030Sstevel@tonic-gate[ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
15040Sstevel@tonic-gate[ -f dir1/syslog.6 ] || exit 1
15050Sstevel@tonic-gate[ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
15060Sstevel@tonic-gate[ -f dir1/syslog.7 ] || exit 1
15070Sstevel@tonic-gate[ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
15080Sstevel@tonic-gate[ -f dir1/syslog.8 ] && exit 1
15090Sstevel@tonic-gate
15100Sstevel@tonic-gate[ -f dir2/messages ] || exit 1
15110Sstevel@tonic-gate[ "xinitially dir2/messages" = "x`/bin/cat dir2/messages`" ] || exit 1
15120Sstevel@tonic-gate[ -f dir2/messages.0 ] || exit 1
15130Sstevel@tonic-gate[ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.0`" ] || exit 1
15140Sstevel@tonic-gate[ -f dir2/messages.1 ] || exit 1
15150Sstevel@tonic-gate[ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.1`" ] || exit 1
15160Sstevel@tonic-gate[ -f dir2/messages.2 ] || exit 1
15170Sstevel@tonic-gate[ "xinitially dir2/messages.2" = "x`/bin/cat dir2/messages.2`" ] || exit 1
15180Sstevel@tonic-gate[ -f dir2/messages.3 ] || exit 1
15190Sstevel@tonic-gate[ "xinitially dir2/messages.3" = "x`/bin/cat dir2/messages.3`" ] || exit 1
15200Sstevel@tonic-gate[ -f dir2/messages.4 ] && exit 1
15210Sstevel@tonic-gateexit 0
15220Sstevel@tonic-gateEOF
15230Sstevel@tonic-gate
15240Sstevel@tonic-gate        set_file('runtest', <<"EOF");
15250Sstevel@tonic-gate# test "logadm9d"
15260Sstevel@tonic-gate$envsetup
1527*12986SJohn.Zolnowsky@Sun.COMexec $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err
15280Sstevel@tonic-gateEOF
15290Sstevel@tonic-gate}
15300Sstevel@tonic-gate
15310Sstevel@tonic-gate###########################################################################
15320Sstevel@tonic-gate#
15330Sstevel@tonic-gate#       logadm10 -- test of size-based rotation check
15340Sstevel@tonic-gate#
15350Sstevel@tonic-gate###########################################################################
15360Sstevel@tonic-gatesub logadm10 {
15370Sstevel@tonic-gate	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
15380Sstevel@tonic-gate	set_file('dir1/syslog', 'initially dir1/syslogXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
15390Sstevel@tonic-gate	set_file('dir1/syslog.0', 'initially dir1/syslog.0');
15400Sstevel@tonic-gate	set_file('dir1/syslog.1', 'initially dir1/syslog.1');
15410Sstevel@tonic-gate	set_file('dir1/syslog.2', 'initially dir1/syslog.2');
15420Sstevel@tonic-gate	set_file('dir1/syslog.3', 'initially dir1/syslog.3');
15430Sstevel@tonic-gate	set_file('dir1/syslog.4', 'initially dir1/syslog.4');
15440Sstevel@tonic-gate	set_file('dir1/syslog.5', 'initially dir1/syslog.5');
15450Sstevel@tonic-gate	set_file('dir1/syslog.6', 'initially dir1/syslog.6');
15460Sstevel@tonic-gate	set_file('dir1/syslog.7', 'initially dir1/syslog.7');
15470Sstevel@tonic-gate	mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
15480Sstevel@tonic-gate	set_file('dir2/messages', 'initially dir2/messages');
15490Sstevel@tonic-gate	set_file('dir2/messages.0', 'initially dir2/messages.0');
15500Sstevel@tonic-gate	set_file('dir2/messages.1', 'initially dir2/messages.1');
15510Sstevel@tonic-gate	set_file('dir2/messages.2', 'initially dir2/messages.2');
15520Sstevel@tonic-gate	set_file('dir2/messages.3', 'initially dir2/messages.3');
15530Sstevel@tonic-gate
15540Sstevel@tonic-gate	set_file('logadm.conf', <<"EOF");
15550Sstevel@tonic-gatedir1/syslog -C 8 -s 30b
15560Sstevel@tonic-gatedir2/messages -C 4 -s 30b
15570Sstevel@tonic-gateEOF
15580Sstevel@tonic-gate
15590Sstevel@tonic-gate	set_file('checktest', <<'EOF');
1560*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
15610Sstevel@tonic-gate[ -s std.out ] && exit 1
15620Sstevel@tonic-gate[ -f dir1/syslog ] || exit 1
15630Sstevel@tonic-gate[ -s dir1/syslog ] && exit 1
15640Sstevel@tonic-gate[ -f dir1/syslog.0 ] || exit 1
15650Sstevel@tonic-gate[ "xinitially dir1/syslogXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
15660Sstevel@tonic-gate[ -f dir1/syslog.1 ] || exit 1
15670Sstevel@tonic-gate[ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
15680Sstevel@tonic-gate[ -f dir1/syslog.2 ] || exit 1
15690Sstevel@tonic-gate[ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
15700Sstevel@tonic-gate[ -f dir1/syslog.3 ] || exit 1
15710Sstevel@tonic-gate[ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
15720Sstevel@tonic-gate[ -f dir1/syslog.4 ] || exit 1
15730Sstevel@tonic-gate[ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
15740Sstevel@tonic-gate[ -f dir1/syslog.5 ] || exit 1
15750Sstevel@tonic-gate[ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
15760Sstevel@tonic-gate[ -f dir1/syslog.6 ] || exit 1
15770Sstevel@tonic-gate[ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
15780Sstevel@tonic-gate[ -f dir1/syslog.7 ] || exit 1
15790Sstevel@tonic-gate[ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
15800Sstevel@tonic-gate[ -f dir1/syslog.8 ] && exit 1
15810Sstevel@tonic-gate
15820Sstevel@tonic-gate[ -f dir2/messages ] || exit 1
15830Sstevel@tonic-gate[ "xinitially dir2/messages" = "x`/bin/cat dir2/messages`" ] || exit 1
15840Sstevel@tonic-gate[ -f dir2/messages.0 ] || exit 1
15850Sstevel@tonic-gate[ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.0`" ] || exit 1
15860Sstevel@tonic-gate[ -f dir2/messages.1 ] || exit 1
15870Sstevel@tonic-gate[ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.1`" ] || exit 1
15880Sstevel@tonic-gate[ -f dir2/messages.2 ] || exit 1
15890Sstevel@tonic-gate[ "xinitially dir2/messages.2" = "x`/bin/cat dir2/messages.2`" ] || exit 1
15900Sstevel@tonic-gate[ -f dir2/messages.3 ] || exit 1
15910Sstevel@tonic-gate[ "xinitially dir2/messages.3" = "x`/bin/cat dir2/messages.3`" ] || exit 1
15920Sstevel@tonic-gate[ -f dir2/messages.4 ] && exit 1
15930Sstevel@tonic-gateexit 0
15940Sstevel@tonic-gateEOF
15950Sstevel@tonic-gate
15960Sstevel@tonic-gate        set_file('runtest', <<"EOF");
15970Sstevel@tonic-gate# test "logadm10"
15980Sstevel@tonic-gate$envsetup
1599*12986SJohn.Zolnowsky@Sun.COMexec $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err
16000Sstevel@tonic-gateEOF
16010Sstevel@tonic-gate}
16020Sstevel@tonic-gate
16030Sstevel@tonic-gate###########################################################################
16040Sstevel@tonic-gate#
16050Sstevel@tonic-gate#       logadm11 -- test of size-based expiration check
16060Sstevel@tonic-gate#
16070Sstevel@tonic-gate###########################################################################
16080Sstevel@tonic-gatesub logadm11 {
16090Sstevel@tonic-gate	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
16100Sstevel@tonic-gate	set_file('dir1/syslog', 'initially dir1/syslog');
16110Sstevel@tonic-gate	set_file('dir1/syslog.0', 'initially dir1/syslog.0');
16120Sstevel@tonic-gate	set_file('dir1/syslog.1', 'initially dir1/syslog.1');
16130Sstevel@tonic-gate	set_file('dir1/syslog.2', 'initially dir1/syslog.2');
16140Sstevel@tonic-gate	set_file('dir1/syslog.3', 'initially dir1/syslog.3');
16150Sstevel@tonic-gate	set_file('dir1/syslog.4', 'initially dir1/syslog.4');
16160Sstevel@tonic-gate	set_file('dir1/syslog.5', 'initially dir1/syslog.5');
16170Sstevel@tonic-gate	set_file('dir1/syslog.6', 'initially dir1/syslog.6');
16180Sstevel@tonic-gate	set_file('dir1/syslog.7', 'initially dir1/syslog.7');
16190Sstevel@tonic-gate	mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
16200Sstevel@tonic-gate	set_file('dir2/messages', 'initially dir2/messages');
16210Sstevel@tonic-gate	set_file('dir2/messages.0', 'initially dir2/messages.0');
16220Sstevel@tonic-gate	set_file('dir2/messages.1', 'initially dir2/messages.1');
16230Sstevel@tonic-gate	set_file('dir2/messages.2', 'initially dir2/messages.2');
16240Sstevel@tonic-gate	set_file('dir2/messages.3', 'initially dir2/messages.3');
16250Sstevel@tonic-gate
16260Sstevel@tonic-gate	set_file('logadm.conf', <<"EOF");
16270Sstevel@tonic-gatedir1/syslog -C 8 -s 30b -S 75b
16280Sstevel@tonic-gatedir2/messages -C 4 -s 30b -S 75b
16290Sstevel@tonic-gateEOF
16300Sstevel@tonic-gate
16310Sstevel@tonic-gate	set_file('checktest', <<'EOF');
1632*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
16330Sstevel@tonic-gate[ -s std.out ] && exit 1
16340Sstevel@tonic-gate[ -f dir1/syslog ] || exit 1
16350Sstevel@tonic-gate[ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog`" ] || exit 1
16360Sstevel@tonic-gate[ -f dir1/syslog.0 ] || exit 1
16370Sstevel@tonic-gate[ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
16380Sstevel@tonic-gate[ -f dir1/syslog.1 ] || exit 1
16390Sstevel@tonic-gate[ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
16400Sstevel@tonic-gate[ -f dir1/syslog.2 ] || exit 1
16410Sstevel@tonic-gate[ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
16420Sstevel@tonic-gate[ -f dir1/syslog.3 ] && exit 1
16430Sstevel@tonic-gate[ -f dir1/syslog.4 ] && exit 1
16440Sstevel@tonic-gate[ -f dir1/syslog.5 ] && exit 1
16450Sstevel@tonic-gate[ -f dir1/syslog.6 ] && exit 1
16460Sstevel@tonic-gate[ -f dir1/syslog.7 ] && exit 1
16470Sstevel@tonic-gate[ -f dir1/syslog.8 ] && exit 1
16480Sstevel@tonic-gate
16490Sstevel@tonic-gate[ -f dir2/messages ] || exit 1
16500Sstevel@tonic-gate[ "xinitially dir2/messages" = "x`/bin/cat dir2/messages`" ] || exit 1
16510Sstevel@tonic-gate[ -f dir2/messages.0 ] || exit 1
16520Sstevel@tonic-gate[ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.0`" ] || exit 1
16530Sstevel@tonic-gate[ -f dir2/messages.1 ] || exit 1
16540Sstevel@tonic-gate[ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.1`" ] || exit 1
16550Sstevel@tonic-gate[ -f dir2/messages.2 ] || exit 1
16560Sstevel@tonic-gate[ "xinitially dir2/messages.2" = "x`/bin/cat dir2/messages.2`" ] || exit 1
16570Sstevel@tonic-gate[ -f dir2/messages.3 ] && exit 1
16580Sstevel@tonic-gate[ -f dir2/messages.4 ] && exit 1
16590Sstevel@tonic-gateexit 0
16600Sstevel@tonic-gateEOF
16610Sstevel@tonic-gate
16620Sstevel@tonic-gate        set_file('runtest', <<"EOF");
16630Sstevel@tonic-gate# test "logadm11"
16640Sstevel@tonic-gate$envsetup
1665*12986SJohn.Zolnowsky@Sun.COMexec $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err
16660Sstevel@tonic-gateEOF
16670Sstevel@tonic-gate}
16680Sstevel@tonic-gate
16690Sstevel@tonic-gate###########################################################################
16700Sstevel@tonic-gate#
16710Sstevel@tonic-gate#	logadm12 -- ENOENT error path
16720Sstevel@tonic-gate#
16730Sstevel@tonic-gate###########################################################################
16740Sstevel@tonic-gatesub logadm12 {
16750Sstevel@tonic-gate	set_file('std.err.expect', <<'EOF');
16760Sstevel@tonic-gatelogadm: Warning: logfile: No such file or directory
16770Sstevel@tonic-gateEOF
16780Sstevel@tonic-gate
16790Sstevel@tonic-gate	set_file('checktest', <<"EOF");
16800Sstevel@tonic-gate[ -s std.out ] && exit 1
1681*12986SJohn.Zolnowsky@Sun.COMexec /bin/diff std.err.expect std.err
16820Sstevel@tonic-gateEOF
16830Sstevel@tonic-gate
16840Sstevel@tonic-gate	set_file('runtest', <<"EOF");
16850Sstevel@tonic-gate# test "logadm12"
16860Sstevel@tonic-gate$envsetup
16870Sstevel@tonic-gateexec $bindir/logadm -f /dev/null logfile >std.out 2>std.err
16880Sstevel@tonic-gateEOF
16890Sstevel@tonic-gate}
16900Sstevel@tonic-gate
16910Sstevel@tonic-gate###########################################################################
16920Sstevel@tonic-gate#
16930Sstevel@tonic-gate#	logadm13 -- ENOENT error path with -N flag
16940Sstevel@tonic-gate#
16950Sstevel@tonic-gate###########################################################################
16960Sstevel@tonic-gatesub logadm13 {
16970Sstevel@tonic-gate	set_file('checktest', <<"EOF");
1698*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
16990Sstevel@tonic-gate[ -s std.out ] && exit 1
17000Sstevel@tonic-gateexit 0
17010Sstevel@tonic-gateEOF
17020Sstevel@tonic-gate
17030Sstevel@tonic-gate	set_file('runtest', <<"EOF");
17040Sstevel@tonic-gate# test "logadm13"
17050Sstevel@tonic-gate$envsetup
17060Sstevel@tonic-gateexec $bindir/logadm -N -f /dev/null logfile >std.out 2>std.err
17070Sstevel@tonic-gateEOF
17080Sstevel@tonic-gate}
17090Sstevel@tonic-gate
17100Sstevel@tonic-gate###########################################################################
17110Sstevel@tonic-gate#
17120Sstevel@tonic-gate#       logadm14 -- test of -n and -v flags
17130Sstevel@tonic-gate#
17140Sstevel@tonic-gate###########################################################################
17150Sstevel@tonic-gatesub logadm14 {
17160Sstevel@tonic-gate	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
17170Sstevel@tonic-gate	set_file('dir1/syslog', 'initially dir1/syslog');
17180Sstevel@tonic-gate	set_file('dir1/syslog.0', 'initially dir1/syslog.0');
17190Sstevel@tonic-gate	set_file('dir1/syslog.1', 'initially dir1/syslog.1');
17200Sstevel@tonic-gate	set_file('dir1/syslog.2', 'initially dir1/syslog.2');
17210Sstevel@tonic-gate	set_file('dir1/syslog.3', 'initially dir1/syslog.3');
17220Sstevel@tonic-gate	set_file('dir1/syslog.4', 'initially dir1/syslog.4');
17230Sstevel@tonic-gate	set_file('dir1/syslog.5', 'initially dir1/syslog.5');
17240Sstevel@tonic-gate	set_file('dir1/syslog.6', 'initially dir1/syslog.6');
17250Sstevel@tonic-gate	set_file('dir1/syslog.7', 'initially dir1/syslog.7');
17260Sstevel@tonic-gate	mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
17270Sstevel@tonic-gate	set_file('dir2/messages', 'initially dir2/messages');
17280Sstevel@tonic-gate	set_file('dir2/messages.0', 'initially dir2/messages.0');
17290Sstevel@tonic-gate	set_file('dir2/messages.1', 'initially dir2/messages.1');
17300Sstevel@tonic-gate	set_file('dir2/messages.2', 'initially dir2/messages.2');
17310Sstevel@tonic-gate	set_file('dir2/messages.3', 'initially dir2/messages.3');
17320Sstevel@tonic-gate
17330Sstevel@tonic-gate	set_file('logadm.conf', <<'EOF');
17340Sstevel@tonic-gate#
17350Sstevel@tonic-gate# logadm.conf
17360Sstevel@tonic-gate#
17370Sstevel@tonic-gate# Default settings for system log file management.
17380Sstevel@tonic-gate# The -w option to logadm(1M) is the preferred way to write to this file,
17390Sstevel@tonic-gate# but if you do edit it by hand, use "logadm -V" to check it for errors.
17400Sstevel@tonic-gate# but if you do edit it by hand, use "logadm -V" to check it for errors.
17410Sstevel@tonic-gate#
17420Sstevel@tonic-gate# The format of lines in this file is:
17430Sstevel@tonic-gate#       <logname> <options>
17440Sstevel@tonic-gate# For each logname listed here, the default options to logadm
17450Sstevel@tonic-gate# are given.  Options given on the logadm command line override
17460Sstevel@tonic-gate# the defaults contained in this file.
17470Sstevel@tonic-gate#
17480Sstevel@tonic-gate# logadm typically runs early every morning via an entry in
17490Sstevel@tonic-gate# root's crontab (see crontab(1)).
17500Sstevel@tonic-gate#
17510Sstevel@tonic-gatedir1/syslog -C 8 -a 'echo kill -HUP `cat /etc/syslog.pid` >> cmd.out'
17520Sstevel@tonic-gatedir2/messages -C 4 -a 'echo kill -HUP `cat /etc/syslog.pid` >> cmd.out'
17530Sstevel@tonic-gate#
17540Sstevel@tonic-gate# The entry below is used by turnacct(1M)
17550Sstevel@tonic-gate#
17560Sstevel@tonic-gate/var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
17570Sstevel@tonic-gateEOF
17580Sstevel@tonic-gate
17590Sstevel@tonic-gate	$gid = $);
17600Sstevel@tonic-gate	$gid =~ s/ .*//;
17610Sstevel@tonic-gate	set_file('grep.out.expect', <<'EOF'.<<"EOF".<<'EOF'.<<"EOF".<<'EOF');
17620Sstevel@tonic-gate# loading logadm.conf
17630Sstevel@tonic-gate# processing logname: dir1/syslog
17640Sstevel@tonic-gate#     using default rotate rules: -s1b -p1w
17650Sstevel@tonic-gate#     using default template: $file.$n
17660Sstevel@tonic-gatemkdir -p dir1 # verify directory exists
17670Sstevel@tonic-gatemv -f dir1/syslog.7 dir1/syslog.8 # rotate log file
17680Sstevel@tonic-gatemkdir -p dir1 # verify directory exists
17690Sstevel@tonic-gatemv -f dir1/syslog.6 dir1/syslog.7 # rotate log file
17700Sstevel@tonic-gatemkdir -p dir1 # verify directory exists
17710Sstevel@tonic-gatemv -f dir1/syslog.5 dir1/syslog.6 # rotate log file
17720Sstevel@tonic-gatemkdir -p dir1 # verify directory exists
17730Sstevel@tonic-gatemv -f dir1/syslog.4 dir1/syslog.5 # rotate log file
17740Sstevel@tonic-gatemkdir -p dir1 # verify directory exists
17750Sstevel@tonic-gatemv -f dir1/syslog.3 dir1/syslog.4 # rotate log file
17760Sstevel@tonic-gatemkdir -p dir1 # verify directory exists
17770Sstevel@tonic-gatemv -f dir1/syslog.2 dir1/syslog.3 # rotate log file
17780Sstevel@tonic-gatemkdir -p dir1 # verify directory exists
17790Sstevel@tonic-gatemv -f dir1/syslog.1 dir1/syslog.2 # rotate log file
17800Sstevel@tonic-gatemkdir -p dir1 # verify directory exists
17810Sstevel@tonic-gatemv -f dir1/syslog.0 dir1/syslog.1 # rotate log file
17820Sstevel@tonic-gatemkdir -p dir1 # verify directory exists
17830Sstevel@tonic-gatemv -f dir1/syslog dir1/syslog.0 # rotate log file
17840Sstevel@tonic-gatetouch dir1/syslog
17850Sstevel@tonic-gateEOF
17860Sstevel@tonic-gatechown $>:$gid dir1/syslog
17870Sstevel@tonic-gateEOF
17880Sstevel@tonic-gatechmod 664 dir1/syslog
17890Sstevel@tonic-gate# processing logname: dir2/messages
17900Sstevel@tonic-gate#     using default rotate rules: -s1b -p1w
17910Sstevel@tonic-gate#     using default template: $file.$n
17920Sstevel@tonic-gatemkdir -p dir2 # verify directory exists
17930Sstevel@tonic-gatemv -f dir2/messages.3 dir2/messages.4 # rotate log file
17940Sstevel@tonic-gatemkdir -p dir2 # verify directory exists
17950Sstevel@tonic-gatemv -f dir2/messages.2 dir2/messages.3 # rotate log file
17960Sstevel@tonic-gatemkdir -p dir2 # verify directory exists
17970Sstevel@tonic-gatemv -f dir2/messages.1 dir2/messages.2 # rotate log file
17980Sstevel@tonic-gatemkdir -p dir2 # verify directory exists
17990Sstevel@tonic-gatemv -f dir2/messages.0 dir2/messages.1 # rotate log file
18000Sstevel@tonic-gatemkdir -p dir2 # verify directory exists
18010Sstevel@tonic-gatemv -f dir2/messages dir2/messages.0 # rotate log file
18020Sstevel@tonic-gatetouch dir2/messages
18030Sstevel@tonic-gateEOF
18040Sstevel@tonic-gatechown $>:$gid dir2/messages
18050Sstevel@tonic-gateEOF
18060Sstevel@tonic-gatechmod 664 dir2/messages
18070Sstevel@tonic-gate# processing logname: /var/adm/pacct
18080Sstevel@tonic-gate#     using default template: $file.$n
18090Sstevel@tonic-gatesh -c echo kill -HUP `cat /etc/syslog.pid` >> cmd.out # -a cmd
1810*12986SJohn.Zolnowsky@Sun.COM# logadm.conf and logadm.timestamps unchanged
18110Sstevel@tonic-gateEOF
18120Sstevel@tonic-gate
18130Sstevel@tonic-gate	set_file('checktest', <<'EOF');
1814*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
18150Sstevel@tonic-gate[ -f std.out ] || exit 1
18160Sstevel@tonic-gate[ -f dir1/syslog ] || exit 1
18170Sstevel@tonic-gate[ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog`" ] || exit 1
18180Sstevel@tonic-gate[ -f dir1/syslog.0 ] || exit 1
18190Sstevel@tonic-gate[ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
18200Sstevel@tonic-gate[ -f dir1/syslog.1 ] || exit 1
18210Sstevel@tonic-gate[ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
18220Sstevel@tonic-gate[ -f dir1/syslog.2 ] || exit 1
18230Sstevel@tonic-gate[ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
18240Sstevel@tonic-gate[ -f dir1/syslog.3 ] || exit 1
18250Sstevel@tonic-gate[ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
18260Sstevel@tonic-gate[ -f dir1/syslog.4 ] || exit 1
18270Sstevel@tonic-gate[ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
18280Sstevel@tonic-gate[ -f dir1/syslog.5 ] || exit 1
18290Sstevel@tonic-gate[ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
18300Sstevel@tonic-gate[ -f dir1/syslog.6 ] || exit 1
18310Sstevel@tonic-gate[ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
18320Sstevel@tonic-gate[ -f dir1/syslog.7 ] || exit 1
18330Sstevel@tonic-gate[ "xinitially dir1/syslog.7" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
18340Sstevel@tonic-gate[ -f dir1/syslog.8 ] && exit 1
18350Sstevel@tonic-gate
18360Sstevel@tonic-gate[ -f dir2/messages ] || exit 1
18370Sstevel@tonic-gate[ "xinitially dir2/messages" = "x`/bin/cat dir2/messages`" ] || exit 1
18380Sstevel@tonic-gate[ -f dir2/messages.0 ] || exit 1
18390Sstevel@tonic-gate[ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.0`" ] || exit 1
18400Sstevel@tonic-gate[ -f dir2/messages.1 ] || exit 1
18410Sstevel@tonic-gate[ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.1`" ] || exit 1
18420Sstevel@tonic-gate[ -f dir2/messages.2 ] || exit 1
18430Sstevel@tonic-gate[ "xinitially dir2/messages.2" = "x`/bin/cat dir2/messages.2`" ] || exit 1
18440Sstevel@tonic-gate[ -f dir2/messages.3 ] || exit 1
18450Sstevel@tonic-gate[ "xinitially dir2/messages.3" = "x`/bin/cat dir2/messages.3`" ] || exit 1
18460Sstevel@tonic-gate[ -f dir2/messages.4 ] && exit 1
18470Sstevel@tonic-gate/bin/grep -v 'recording rotation date' std.out > grep.out
1848*12986SJohn.Zolnowsky@Sun.COMexec /bin/diff grep.out.expect grep.out
18490Sstevel@tonic-gateEOF
18500Sstevel@tonic-gate
18510Sstevel@tonic-gate        set_file('runtest', <<"EOF");
18520Sstevel@tonic-gate# test "logadm14"
18530Sstevel@tonic-gate$envsetup
1854*12986SJohn.Zolnowsky@Sun.COMexec $bindir/logadm -nv -f logadm.conf -F logadm.timestamps >std.out 2>std.err
18550Sstevel@tonic-gateEOF
18560Sstevel@tonic-gate}
18570Sstevel@tonic-gate
18580Sstevel@tonic-gate###########################################################################
18590Sstevel@tonic-gate#
18600Sstevel@tonic-gate#	logadm15 -- test of -T
18610Sstevel@tonic-gate#
18620Sstevel@tonic-gate###########################################################################
18630Sstevel@tonic-gatesub logadm15 {
18640Sstevel@tonic-gate	set_file('logfile', '');
18650Sstevel@tonic-gate	set_file('logfile.0', 'initially logfile.0');
18660Sstevel@tonic-gate	set_file('logfile.1', 'initially logfile.1');
18670Sstevel@tonic-gate	set_file('logfile.2', 'initially logfile.2');
18680Sstevel@tonic-gate	set_file('logfile.3', 'initially logfile.3');
18690Sstevel@tonic-gate	set_file('logfile.4', 'initially logfile.4');
18700Sstevel@tonic-gate	set_file('logfile.5', 'initially logfile.5');
18710Sstevel@tonic-gate	set_file('logfile.6', 'initially logfile.6');
18720Sstevel@tonic-gate	set_file('logfile.7', 'initially logfile.7');
18730Sstevel@tonic-gate	set_file('logfile.8', 'initially logfile.8');
18740Sstevel@tonic-gate	set_file('logfile.9', 'initially logfile.9');
18750Sstevel@tonic-gate
18760Sstevel@tonic-gate	set_file('checktest', <<'EOF');
1877*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
18780Sstevel@tonic-gate[ -s std.out ] && exit 1
18790Sstevel@tonic-gate[ -f logfile ] || exit 1
18800Sstevel@tonic-gate[ "x" = "x`/bin/cat logfile`" ] || exit 1
18810Sstevel@tonic-gate[ -f logfile.0 ] || exit 1
18820Sstevel@tonic-gate[ "xinitially logfile.0" = "x`/bin/cat logfile.0`" ] || exit 1
18830Sstevel@tonic-gate[ -f logfile.1 ] || exit 1
18840Sstevel@tonic-gate[ "xinitially logfile.1" = "x`/bin/cat logfile.1`" ] || exit 1
18850Sstevel@tonic-gate[ -f logfile.2 ] || exit 1
18860Sstevel@tonic-gate[ "xinitially logfile.2" = "x`/bin/cat logfile.2`" ] || exit 1
18870Sstevel@tonic-gate[ -f logfile.3 ] && exit 1
18880Sstevel@tonic-gate[ -f logfile.4 ] || exit 1
18890Sstevel@tonic-gate[ "xinitially logfile.4" = "x`/bin/cat logfile.4`" ] || exit 1
18900Sstevel@tonic-gate[ -f logfile.5 ] && exit 1
18910Sstevel@tonic-gate[ -f logfile.6 ] || exit 1
18920Sstevel@tonic-gate[ "xinitially logfile.6" = "x`/bin/cat logfile.6`" ] || exit 1
18930Sstevel@tonic-gate[ -f logfile.7 ] && exit 1
18940Sstevel@tonic-gate[ -f logfile.8 ] || exit 1
18950Sstevel@tonic-gate[ "xinitially logfile.8" = "x`/bin/cat logfile.8`" ] || exit 1
18960Sstevel@tonic-gate[ -f logfile.9 ] && exit 1
18970Sstevel@tonic-gate[ -f logfile.10 ] && exit 1
18980Sstevel@tonic-gateexit 0
18990Sstevel@tonic-gateEOF
19000Sstevel@tonic-gate
19010Sstevel@tonic-gate	set_file('runtest', <<"EOF");
19020Sstevel@tonic-gate# test "logadm15"
19030Sstevel@tonic-gate$envsetup
19040Sstevel@tonic-gateexec $bindir/logadm -f /dev/null logfile -C1 -T '*.[13579]'>std.out 2>std.err
19050Sstevel@tonic-gateEOF
19060Sstevel@tonic-gate}
19070Sstevel@tonic-gate
19080Sstevel@tonic-gate###########################################################################
19090Sstevel@tonic-gate#
19100Sstevel@tonic-gate#	logadm16 -- test of -h
19110Sstevel@tonic-gate#
19120Sstevel@tonic-gate###########################################################################
19130Sstevel@tonic-gatesub logadm16 {
19140Sstevel@tonic-gate	set_file('std.err.expect', <<'EOF');
19150Sstevel@tonic-gateUsage: logadm [options]
19160Sstevel@tonic-gate       (processes all entries in /etc/logadm.conf or conffile given by -f)
19170Sstevel@tonic-gate   or: logadm [options] logname...
19180Sstevel@tonic-gate       (processes the given lognames)
19190Sstevel@tonic-gate
19200Sstevel@tonic-gateGeneral options:
19210Sstevel@tonic-gate        -e mailaddr     mail errors to given address
1922*12986SJohn.Zolnowsky@Sun.COM        -F timestamps   use timestamps instead of /var/logadm/timestamps
19230Sstevel@tonic-gate        -f conffile     use conffile instead of /etc/logadm.conf
19240Sstevel@tonic-gate        -h              display help
19250Sstevel@tonic-gate        -N              not an error if log file nonexistent
19260Sstevel@tonic-gate        -n              show actions, don't perform them
19270Sstevel@tonic-gate        -r              remove logname entry from conffile
19280Sstevel@tonic-gate        -V              ensure conffile entries exist, correct
19290Sstevel@tonic-gate        -v              print info about actions happening
19300Sstevel@tonic-gate        -w entryname    write entry to config file
19310Sstevel@tonic-gate
19320Sstevel@tonic-gateOptions which control when a logfile is rotated:
19330Sstevel@tonic-gate(default is: -s1b -p1w if no -s or -p)
19340Sstevel@tonic-gate        -p period       only rotate if period passed since last rotate
19350Sstevel@tonic-gate        -P timestamp    used to store rotation date in conffile
19360Sstevel@tonic-gate        -s size         only rotate if given size or greater
19370Sstevel@tonic-gate
19380Sstevel@tonic-gateOptions which control how a logfile is rotated:
19390Sstevel@tonic-gate(default is: -t '$file.$n', owner/group/mode taken from log file)
19400Sstevel@tonic-gate        -a cmd          execute cmd after taking actions
19410Sstevel@tonic-gate        -b cmd          execute cmd before taking actions
19420Sstevel@tonic-gate        -c              copy & truncate logfile, don't rename
19430Sstevel@tonic-gate        -g group        new empty log file group
1944954Sgm149974        -l              rotate log file with local time rather than UTC
19450Sstevel@tonic-gate        -m mode         new empty log file mode
19460Sstevel@tonic-gate        -M cmd          execute cmd to rotate the log file
19470Sstevel@tonic-gate        -o owner        new empty log file owner
19480Sstevel@tonic-gate        -R cmd          run cmd on file after rotate
19490Sstevel@tonic-gate        -t template     template for naming old logs
19500Sstevel@tonic-gate        -z count        gzip old logs except most recent count
19510Sstevel@tonic-gate
19520Sstevel@tonic-gateOptions which control the expiration of old logfiles:
19530Sstevel@tonic-gate(default is: -C10 if no -A, -C, or -S)
19540Sstevel@tonic-gate        -A age          expire logs older than age
19550Sstevel@tonic-gate        -C count        expire old logs until count remain
19560Sstevel@tonic-gate        -E cmd          run cmd on file to expire
19570Sstevel@tonic-gate        -S size         expire until space used is below size
19580Sstevel@tonic-gate        -T pattern      pattern for finding old logs
19590Sstevel@tonic-gateEOF
19600Sstevel@tonic-gate
19610Sstevel@tonic-gate	set_file('checktest', <<'EOF');
19620Sstevel@tonic-gate[ -s std.out ] && exit 1
1963*12986SJohn.Zolnowsky@Sun.COMexec /bin/diff std.err.expect std.err
19640Sstevel@tonic-gateEOF
19650Sstevel@tonic-gate
19660Sstevel@tonic-gate	set_file('runtest', <<"EOF");
19670Sstevel@tonic-gate# test "logadm16"
19680Sstevel@tonic-gate$envsetup
19690Sstevel@tonic-gateexec $bindir/logadm -h >std.out 2>std.err
19700Sstevel@tonic-gateEOF
19710Sstevel@tonic-gate}
19720Sstevel@tonic-gate
19730Sstevel@tonic-gate###########################################################################
19740Sstevel@tonic-gate#
19750Sstevel@tonic-gate#       logadm17 -- test that mkdir -p happens as necessary
19760Sstevel@tonic-gate#
19770Sstevel@tonic-gate###########################################################################
19780Sstevel@tonic-gatesub logadm17 {
19790Sstevel@tonic-gate	set_file('logfile', 'initially logfile');
19800Sstevel@tonic-gate
19810Sstevel@tonic-gate	set_file('checktest', <<'EOF');
1982*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
19830Sstevel@tonic-gate[ -s std.out ] && exit 1
19840Sstevel@tonic-gate[ -f dir1/dir2/logfile ] || exit 1
19850Sstevel@tonic-gate[ -f logfile ] || exit 1
19860Sstevel@tonic-gate[ "xinitially logfile" = "x`/bin/cat dir1/dir2/logfile`" ] || exit 1
19870Sstevel@tonic-gateexit 0
19880Sstevel@tonic-gateEOF
19890Sstevel@tonic-gate
19900Sstevel@tonic-gate        set_file('runtest', <<"EOF");
19910Sstevel@tonic-gate# test "logadm17"
19920Sstevel@tonic-gate$envsetup
19930Sstevel@tonic-gateexec $bindir/logadm -f /dev/null -t 'dir1/dir2/\$basename' logfile -p now >std.out 2>std.err
19940Sstevel@tonic-gateEOF
19950Sstevel@tonic-gate}
19960Sstevel@tonic-gate
19970Sstevel@tonic-gate###########################################################################
19980Sstevel@tonic-gate#
19990Sstevel@tonic-gate#       logadm18 -- test of -M option
20000Sstevel@tonic-gate#
20010Sstevel@tonic-gate###########################################################################
20020Sstevel@tonic-gatesub logadm18 {
20030Sstevel@tonic-gate	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
20040Sstevel@tonic-gate	set_file('dir1/syslog', 'initially dir1/syslog');
20050Sstevel@tonic-gate	set_file('dir1/syslog.0', 'initially dir1/syslog.0');
20060Sstevel@tonic-gate	set_file('dir1/syslog.1', 'initially dir1/syslog.1');
20070Sstevel@tonic-gate	set_file('dir1/syslog.2', 'initially dir1/syslog.2');
20080Sstevel@tonic-gate	set_file('dir1/syslog.3', 'initially dir1/syslog.3');
20090Sstevel@tonic-gate	set_file('dir1/syslog.4', 'initially dir1/syslog.4');
20100Sstevel@tonic-gate	set_file('dir1/syslog.5', 'initially dir1/syslog.5');
20110Sstevel@tonic-gate	set_file('dir1/syslog.6', 'initially dir1/syslog.6');
20120Sstevel@tonic-gate	set_file('dir1/syslog.7', 'initially dir1/syslog.7');
20130Sstevel@tonic-gate
20140Sstevel@tonic-gate	set_file('logadm.conf', <<"EOF");
20150Sstevel@tonic-gatedir1/syslog -C 8 -s 1b -M '/bin/tr [a-z] [A-Z] < \$file > \$nfile; /bin/rm -f \$file'
20160Sstevel@tonic-gateEOF
20170Sstevel@tonic-gate
20180Sstevel@tonic-gate	set_file('checktest', <<'EOF');
2019*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
20200Sstevel@tonic-gate[ -s std.out ] && exit 1
20210Sstevel@tonic-gate[ -f dir1/syslog ] || exit 1
20220Sstevel@tonic-gate[ -s dir1/syslog ] && exit 1
20230Sstevel@tonic-gate[ -f dir1/syslog.0 ] || exit 1
20240Sstevel@tonic-gate[ "xINITIALLY DIR1/SYSLOG" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
20250Sstevel@tonic-gate[ -f dir1/syslog.1 ] || exit 1
20260Sstevel@tonic-gate[ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
20270Sstevel@tonic-gate[ -f dir1/syslog.2 ] || exit 1
20280Sstevel@tonic-gate[ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
20290Sstevel@tonic-gate[ -f dir1/syslog.3 ] || exit 1
20300Sstevel@tonic-gate[ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
20310Sstevel@tonic-gate[ -f dir1/syslog.4 ] || exit 1
20320Sstevel@tonic-gate[ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
20330Sstevel@tonic-gate[ -f dir1/syslog.5 ] || exit 1
20340Sstevel@tonic-gate[ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
20350Sstevel@tonic-gate[ -f dir1/syslog.6 ] || exit 1
20360Sstevel@tonic-gate[ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
20370Sstevel@tonic-gate[ -f dir1/syslog.7 ] || exit 1
20380Sstevel@tonic-gate[ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
20390Sstevel@tonic-gate[ -f dir1/syslog.8 ] && exit 1
20400Sstevel@tonic-gate
20410Sstevel@tonic-gateexit 0
20420Sstevel@tonic-gateEOF
20430Sstevel@tonic-gate
20440Sstevel@tonic-gate        set_file('runtest', <<"EOF");
20450Sstevel@tonic-gate# test "logadm18"
20460Sstevel@tonic-gate$envsetup
2047*12986SJohn.Zolnowsky@Sun.COMexec $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err
20480Sstevel@tonic-gateEOF
20490Sstevel@tonic-gate}
2050954Sgm149974
2051954Sgm149974#############################################################################
2052954Sgm149974#
2053954Sgm149974#         logadm19 -- test of  -l
2054954Sgm149974#
2055954Sgm149974#############################################################################
2056954Sgm149974sub logadm19 {
2057954Sgm149974        set_file('logfile', 'initially logfile');
2058954Sgm149974
2059954Sgm149974        set_file('checktest', <<'EOF');
2060*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
2061954Sgm149974[ -s std.out ] && exit 1
2062954Sgm149974[ -s logfile ] && exit 1
2063954Sgm149974TZ= export TZ
2064954Sgm149974d=`/bin/date +\%d\%H\%M`
2065954Sgm149974[ -f logfile.$d ] || exit 1
2066954Sgm149974[ "xinitially logfile" = "x`/bin/cat logfile.$d`" ] || exit 1
2067954Sgm149974exit 0
2068954Sgm149974EOF
2069954Sgm149974
2070954Sgm149974        set_file('runtest', <<"EOF");
2071*12986SJohn.Zolnowsky@Sun.COM# test "logadm19"
2072954Sgm149974$envsetup
2073954Sgm149974exec $bindir/logadm -f /dev/null -l -p now logfile -t '\$file.\%d\%H\%M' >std.out 2>std.err
2074954Sgm149974EOF
2075954Sgm149974}
2076*12986SJohn.Zolnowsky@Sun.COM
2077*12986SJohn.Zolnowsky@Sun.COM#############################################################################
2078*12986SJohn.Zolnowsky@Sun.COM#
2079*12986SJohn.Zolnowsky@Sun.COM#         logadm20 -- test of unquotables/error handling
2080*12986SJohn.Zolnowsky@Sun.COM#
2081*12986SJohn.Zolnowsky@Sun.COM#############################################################################
2082*12986SJohn.Zolnowsky@Sun.COMsub logadm20 {
2083*12986SJohn.Zolnowsky@Sun.COM	set_file('logadm.conf', <<'EOF');
2084*12986SJohn.Zolnowsky@Sun.COM# non-trivial entry
2085*12986SJohn.Zolnowsky@Sun.COM/var/log/syslog -C 8 -a 'kill -HUP `cat /var/run/syslog.pid`'
2086*12986SJohn.Zolnowsky@Sun.COMEOF
2087*12986SJohn.Zolnowsky@Sun.COM
2088*12986SJohn.Zolnowsky@Sun.COM	set_file('std.err.expect', <<'EOF');
2089*12986SJohn.Zolnowsky@Sun.COMlogadm: Error: Can't protect quotes in </bin/echo "She can't take anymore, Cap'n!">
2090*12986SJohn.Zolnowsky@Sun.COMlogadm: Error: unsafe to update configuration file or timestamps
2091*12986SJohn.Zolnowsky@Sun.COMlogadm: Error: bailing out due to command line errors
2092*12986SJohn.Zolnowsky@Sun.COMUse "logadm -h" for help.
2093*12986SJohn.Zolnowsky@Sun.COMexit=1
2094*12986SJohn.Zolnowsky@Sun.COMEOF
2095*12986SJohn.Zolnowsky@Sun.COM
2096*12986SJohn.Zolnowsky@Sun.COM        set_file('checktest', <<'EOF');
2097*12986SJohn.Zolnowsky@Sun.COM[ -s std.err ] || exit 1
2098*12986SJohn.Zolnowsky@Sun.COM[ -s std.out ] && exit 1
2099*12986SJohn.Zolnowsky@Sun.COM[ -f logadm.conf????? ] && exit 1
2100*12986SJohn.Zolnowsky@Sun.COM[ -f logadm.timestamps????? ] && exit 1
2101*12986SJohn.Zolnowsky@Sun.COMexec /bin/diff std.err.expect std.err
2102*12986SJohn.Zolnowsky@Sun.COMEOF
2103*12986SJohn.Zolnowsky@Sun.COM
2104*12986SJohn.Zolnowsky@Sun.COM        set_file('runtest', <<"EOF");
2105*12986SJohn.Zolnowsky@Sun.COM# test "logadm20"
2106*12986SJohn.Zolnowsky@Sun.COM$envsetup
2107*12986SJohn.Zolnowsky@Sun.COM$bindir/logadm -f logadm.conf -F logadm.timestamps -w /a/b/c -p 1w -l -b "/bin/echo \\"She can't take anymore, Cap'n!\\"" >std.out 2>std.err
2108*12986SJohn.Zolnowsky@Sun.COMecho exit=\$? >>std.err
2109*12986SJohn.Zolnowsky@Sun.COMEOF
2110*12986SJohn.Zolnowsky@Sun.COM}
2111