xref: /illumos-gate/usr/src/cmd/logadm/tester (revision bbf21555)
17c478bd9Sstevel@tonic-gate#!/usr/bin/perl -w
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
63010f05bSdp# Common Development and Distribution License (the "License").
73010f05bSdp# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
227c478bd9Sstevel@tonic-gate#
23e9a193fcSJohn.Zolnowsky@Sun.COM# Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
24d5dace52SMike Gerdts# Copyright 2019 Joyent, Inc.
257c478bd9Sstevel@tonic-gate#
267c478bd9Sstevel@tonic-gate#
277c478bd9Sstevel@tonic-gate# tester - run logadm tests
287c478bd9Sstevel@tonic-gate#
297c478bd9Sstevel@tonic-gate# requires a <bindir> argument to say where the various logadm
307c478bd9Sstevel@tonic-gate# binaries live (conftest, globtest, kwtest, luttest, optstest, and
317c478bd9Sstevel@tonic-gate# logadm itself).
327c478bd9Sstevel@tonic-gate#
337c478bd9Sstevel@tonic-gate# to run all the tests:
34d5dace52SMike Gerdts#	tester [-f] <bindir>
357c478bd9Sstevel@tonic-gate#
367c478bd9Sstevel@tonic-gate# to run just a few tests, given their names:
37d5dace52SMike Gerdts#	tester [-f] <bindir> globtest1 luttest1
387c478bd9Sstevel@tonic-gate#
397c478bd9Sstevel@tonic-gate# to setup a test and stop so you can run it by hand:
40d5dace52SMike Gerdts#	tester [-f] -s globtest1 <bindir>
417c478bd9Sstevel@tonic-gate#
42d5dace52SMike Gerdts#	tester will tell you what tmp directory it created for
43d5dace52SMike Gerdts#	the test.  to run it, cd there and run:
44d5dace52SMike Gerdts#		sh runtest
45d5dace52SMike Gerdts#	to check the results, run:
46d5dace52SMike Gerdts#		sh checktest
477c478bd9Sstevel@tonic-gate#
487c478bd9Sstevel@tonic-gate# -f means "fast" -- without it, watchmalloc(3MALLOC) is setup for
497c478bd9Sstevel@tonic-gate# each test and they run a zillion times slower and produce core
507c478bd9Sstevel@tonic-gate# dumps when malloc/free problems are detected.
517c478bd9Sstevel@tonic-gate#
527c478bd9Sstevel@tonic-gate$watchmalloc=1;		# default is to use watchmalloc
537c478bd9Sstevel@tonic-gate${ENV} = "/bin";
547c478bd9Sstevel@tonic-gateumask 002;
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate# list of tests we run by default
577c478bd9Sstevel@tonic-gate@tests = (
587c478bd9Sstevel@tonic-gate	"conftest1",
597c478bd9Sstevel@tonic-gate	"conftest2",
607c478bd9Sstevel@tonic-gate	"globtest1",
617c478bd9Sstevel@tonic-gate	"globtest2",
627c478bd9Sstevel@tonic-gate	"kwtest1",
637c478bd9Sstevel@tonic-gate	"kwtest2",
647c478bd9Sstevel@tonic-gate	"luttest1",
657c478bd9Sstevel@tonic-gate	"optstest1",
667c478bd9Sstevel@tonic-gate	"optstest2",
677c478bd9Sstevel@tonic-gate	"logadmV1",
687c478bd9Sstevel@tonic-gate	"logadmV2",
697c478bd9Sstevel@tonic-gate	"logadmr",
707c478bd9Sstevel@tonic-gate	"logadmw",
717c478bd9Sstevel@tonic-gate	"logadm1",
727c478bd9Sstevel@tonic-gate	"logadm1c",
737c478bd9Sstevel@tonic-gate	"logadm2",
747c478bd9Sstevel@tonic-gate	"logadm3",
757c478bd9Sstevel@tonic-gate	"logadm4",
767c478bd9Sstevel@tonic-gate	"logadm5",
777c478bd9Sstevel@tonic-gate	"logadm6",
787c478bd9Sstevel@tonic-gate	"logadm7",
797c478bd9Sstevel@tonic-gate	"logadm8",
807c478bd9Sstevel@tonic-gate	"logadm9",
817c478bd9Sstevel@tonic-gate	"logadm9d",
827c478bd9Sstevel@tonic-gate	"logadm10",
837c478bd9Sstevel@tonic-gate	"logadm11",
847c478bd9Sstevel@tonic-gate	"logadm12",
857c478bd9Sstevel@tonic-gate	"logadm13",
867c478bd9Sstevel@tonic-gate	"logadm14",
877c478bd9Sstevel@tonic-gate	"logadm15",
887c478bd9Sstevel@tonic-gate	"logadm16",
897c478bd9Sstevel@tonic-gate	"logadm17",
907c478bd9Sstevel@tonic-gate	"logadm18",
91636deb66Sgm	"logadm19",
92e9a193fcSJohn.Zolnowsky@Sun.COM	"logadm20",
93e911f249SSebastian Wiedenroth	"logadm21",
94e911f249SSebastian Wiedenroth	"logadm22",
95d5dace52SMike Gerdts	"logadm23",
96d5dace52SMike Gerdts	"stderr1"
977c478bd9Sstevel@tonic-gate);
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gateuse Getopt::Std;
1007c478bd9Sstevel@tonic-gateuse File::Find;
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate$usage_summary = '[-s test-name] [-d dir] bindir [test-name...]';
1037c478bd9Sstevel@tonic-gate$usage_getopts = 'fd:s:';
1047c478bd9Sstevel@tonic-gate%usage = (
1057c478bd9Sstevel@tonic-gate	d=>'use dir for tests rather than creating one in /tmp',
1067c478bd9Sstevel@tonic-gate	s=>'setup only, do not run test');
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate# spew usage message, plus any given message, and exit
1097c478bd9Sstevel@tonic-gatesub usage {
1107c478bd9Sstevel@tonic-gate	my $msg = shift;
1117c478bd9Sstevel@tonic-gate
1127c478bd9Sstevel@tonic-gate	if ($msg) {
1137c478bd9Sstevel@tonic-gate		chomp $msg;
1147c478bd9Sstevel@tonic-gate		warn "$0: $msg\n" if $msg;
1157c478bd9Sstevel@tonic-gate	}
1167c478bd9Sstevel@tonic-gate	warn "Usage: $0 $usage_summary\n";
1177c478bd9Sstevel@tonic-gate	foreach (sort keys %usage) {
1187c478bd9Sstevel@tonic-gate		warn "       -$_ $usage{$_}\n";
1197c478bd9Sstevel@tonic-gate	}
1207c478bd9Sstevel@tonic-gate	exit 1;
1217c478bd9Sstevel@tonic-gate}
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate#
1247c478bd9Sstevel@tonic-gate# basic argument processing
1257c478bd9Sstevel@tonic-gate#
1267c478bd9Sstevel@tonic-gate$myname = $0;
1277c478bd9Sstevel@tonic-gate$myname =~ s/.*\///;	# just show last component in error mesages
1287c478bd9Sstevel@tonic-gategetopts($usage_getopts) or usage;
1297c478bd9Sstevel@tonic-gate$bindir = shift or usage;
1307c478bd9Sstevel@tonic-gateusage("$bindir does not exist") unless -d $bindir;
1317c478bd9Sstevel@tonic-gateusage("cannot list more than one test with -s option") if $opt_s && @ARGV;
1327c478bd9Sstevel@tonic-gate@tests = @ARGV if @ARGV;
1337c478bd9Sstevel@tonic-gateprint "Fast mode\n" if $opt_f;
1347c478bd9Sstevel@tonic-gate$watchmalloc = 0 if $opt_f;
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate$mydir=`pwd`;
1377c478bd9Sstevel@tonic-gatechomp $mydir;
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate$dir = $opt_d;
1407c478bd9Sstevel@tonic-gate$dir = "/tmp/logadmtest$$" unless $dir = $opt_d;
1417c478bd9Sstevel@tonic-gate
1427c478bd9Sstevel@tonic-gateif (!-d $dir) {
1437c478bd9Sstevel@tonic-gate	mkdir $dir, 0777 or die "$myname: mkdir $dir: $!\n";
1447c478bd9Sstevel@tonic-gate	$needrmdir = 1;
1457c478bd9Sstevel@tonic-gate}
1467c478bd9Sstevel@tonic-gate
1477c478bd9Sstevel@tonic-gatechdir $dir or die "$myname: $dir: $!\n";
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate# common commands in runtest by tests
1507c478bd9Sstevel@tonic-gateif ($watchmalloc) {
1517c478bd9Sstevel@tonic-gate	$envsetup =
1527c478bd9Sstevel@tonic-gate		"HOME=$dir export HOME; " .
1537c478bd9Sstevel@tonic-gate		"LD_PRELOAD=watchmalloc.so.1 export LD_PRELOAD; " .
1547c478bd9Sstevel@tonic-gate		"MALLOC_DEBUG=RW export MALLOC_DEBUG";
1557c478bd9Sstevel@tonic-gate} else {
1567c478bd9Sstevel@tonic-gate	$envsetup = "HOME=$dir export HOME; ";
1577c478bd9Sstevel@tonic-gate}
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate$| = 1;		# a.k.a. setbuf(stdout, NULL)
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gateif ($opt_s) {
1627c478bd9Sstevel@tonic-gate	#
1637c478bd9Sstevel@tonic-gate	# just setup the test, explain how to use it, and exit
1647c478bd9Sstevel@tonic-gate	#
1657c478bd9Sstevel@tonic-gate	$testname = $opt_s;
1667c478bd9Sstevel@tonic-gate	eval "&$opt_s";
1677c478bd9Sstevel@tonic-gate	die "$myname: ERROR: $@" if $@;
1687c478bd9Sstevel@tonic-gate	print "$myname: $testname setup complete, to run, cd to:\n";
1697c478bd9Sstevel@tonic-gate	print "    $dir\n";
1707c478bd9Sstevel@tonic-gate	print "and run the command:\n";
1717c478bd9Sstevel@tonic-gate	print "    sh runtest\n";
1727c478bd9Sstevel@tonic-gate	print "to check the results, run the command:\n";
1737c478bd9Sstevel@tonic-gate	print "    sh checktest\n";
1747c478bd9Sstevel@tonic-gate	exit 0;
1757c478bd9Sstevel@tonic-gate} else {
1767c478bd9Sstevel@tonic-gate	#
1777c478bd9Sstevel@tonic-gate	# run all the tests
1787c478bd9Sstevel@tonic-gate	#
1797c478bd9Sstevel@tonic-gate	foreach (@tests) {
1807c478bd9Sstevel@tonic-gate		$testname = $_;
1817c478bd9Sstevel@tonic-gate		print "Running $testname...";
1827c478bd9Sstevel@tonic-gate		eval "&$_";
1837c478bd9Sstevel@tonic-gate		if ($@) {
1847c478bd9Sstevel@tonic-gate			print " SETUP FAILURE\n";
1857c478bd9Sstevel@tonic-gate			print STDERR "$myname: ERROR: $@";
1867c478bd9Sstevel@tonic-gate			exit 1;
1877c478bd9Sstevel@tonic-gate		}
1887c478bd9Sstevel@tonic-gate		eval "runner('runtest')";
1897c478bd9Sstevel@tonic-gate		if ($@) {
1907c478bd9Sstevel@tonic-gate			print " RUNTEST FAILURE\n";
1917c478bd9Sstevel@tonic-gate			print STDERR "$myname: ERROR: $@";
1927c478bd9Sstevel@tonic-gate			print STDERR "results captured in directory $dir\n";
1937c478bd9Sstevel@tonic-gate			print STDERR "  or use: $myname -s $testname $bindir\n";
1947c478bd9Sstevel@tonic-gate			print STDERR "  to do a fresh setup of this test.\n";
1957c478bd9Sstevel@tonic-gate			exit 1;
1967c478bd9Sstevel@tonic-gate		}
197e9a193fcSJohn.Zolnowsky@Sun.COM		eval "runner('checktest', '-x', '> checktest.out 2>&1')";
1987c478bd9Sstevel@tonic-gate		if ($@) {
1997c478bd9Sstevel@tonic-gate			print " CHECKTEST FAILURE\n";
2007c478bd9Sstevel@tonic-gate			print STDERR "$myname: ERROR: $@";
201e9a193fcSJohn.Zolnowsky@Sun.COM			print STDERR "results captured in file $dir/checktest.out\n";
2027c478bd9Sstevel@tonic-gate			print STDERR "  or use: $myname -s $testname $bindir\n";
2037c478bd9Sstevel@tonic-gate			print STDERR "  to do a fresh setup of this test.\n";
2047c478bd9Sstevel@tonic-gate			exit 1;
2057c478bd9Sstevel@tonic-gate		}
2067c478bd9Sstevel@tonic-gate		print "pass\n";
2077c478bd9Sstevel@tonic-gate		# sanity...
2087c478bd9Sstevel@tonic-gate		die "unexpected dir $dir" unless $dir =~ m,/.+/,;
2097c478bd9Sstevel@tonic-gate		system("/bin/rm -rf $dir/*");
2107c478bd9Sstevel@tonic-gate	}
2117c478bd9Sstevel@tonic-gate}
2127c478bd9Sstevel@tonic-gate
2137c478bd9Sstevel@tonic-gate# if we were the ones who created $dir, remove it
2147c478bd9Sstevel@tonic-gateif ($needrmdir) {
2157c478bd9Sstevel@tonic-gate	chdir $mydir;
2167c478bd9Sstevel@tonic-gate	rmdir $dir || die "$myname: rmdir $dir: $!\n";
2177c478bd9Sstevel@tonic-gate}
2187c478bd9Sstevel@tonic-gate
2197c478bd9Sstevel@tonic-gateexit 0;
2207c478bd9Sstevel@tonic-gate
2217c478bd9Sstevel@tonic-gate#
2227c478bd9Sstevel@tonic-gate# run a shell script and check for failure
2237c478bd9Sstevel@tonic-gate#
2247c478bd9Sstevel@tonic-gate# the shell scripts generated by this program always "exec" the binary
2257c478bd9Sstevel@tonic-gate# under test so checking here are for exit code, signals, and core dump
2267c478bd9Sstevel@tonic-gate# is actually checking the program under test and not /bin/sh
2277c478bd9Sstevel@tonic-gate#
2287c478bd9Sstevel@tonic-gatesub runner {
229e9a193fcSJohn.Zolnowsky@Sun.COM	my ($cmd, $prefix, $suffix) = (@_, '', '');
230e9a193fcSJohn.Zolnowsky@Sun.COM
231e9a193fcSJohn.Zolnowsky@Sun.COM	my $fullcmd = "/bin/sh $prefix $cmd $suffix";
2327c478bd9Sstevel@tonic-gate	my $rc = 0xffff & system("$fullcmd");
2337c478bd9Sstevel@tonic-gate
2347c478bd9Sstevel@tonic-gate	if ($rc == 0) {
2357c478bd9Sstevel@tonic-gate		return;		# cmd completed normally
2367c478bd9Sstevel@tonic-gate	} elsif ($rc == 0xff00) {
2377c478bd9Sstevel@tonic-gate		die "command \"$cmd\" failed: $!\n";
2387c478bd9Sstevel@tonic-gate	} elsif (($rc & 0xff) == 0) {
2397c478bd9Sstevel@tonic-gate		$rc >>= 8;
2407c478bd9Sstevel@tonic-gate		die "command \"$cmd\" exit $rc\n";
2417c478bd9Sstevel@tonic-gate	} else {
2427c478bd9Sstevel@tonic-gate		my $coremsg;
2437c478bd9Sstevel@tonic-gate		$coremsg = " (core dumped)" if ($rc & 0x80);
2447c478bd9Sstevel@tonic-gate		$rc &= ~0x80;
2457c478bd9Sstevel@tonic-gate		die "command \"$cmd\" signal $rc$coremsg\n" ;
2467c478bd9Sstevel@tonic-gate	}
2477c478bd9Sstevel@tonic-gate}
2487c478bd9Sstevel@tonic-gate
2497c478bd9Sstevel@tonic-gate#
2507c478bd9Sstevel@tonic-gate# set_file(filename [, contents]) -- create a file, optionally with contents
2517c478bd9Sstevel@tonic-gate#
2527c478bd9Sstevel@tonic-gatesub set_file {
2537c478bd9Sstevel@tonic-gate	my $file = shift;
2547c478bd9Sstevel@tonic-gate	my $contents = shift;
2557c478bd9Sstevel@tonic-gate
2567c478bd9Sstevel@tonic-gate	open SF, ">$file" or die "create \"$file\": $!\n";
2577c478bd9Sstevel@tonic-gate	print SF $contents if defined($contents);
2587c478bd9Sstevel@tonic-gate	close SF;
2597c478bd9Sstevel@tonic-gate}
2607c478bd9Sstevel@tonic-gate
2617c478bd9Sstevel@tonic-gate#############
2627c478bd9Sstevel@tonic-gate#############
2637c478bd9Sstevel@tonic-gate#############    THE TESTS START AFTER HERE...
2647c478bd9Sstevel@tonic-gate#############
2657c478bd9Sstevel@tonic-gate#############
2667c478bd9Sstevel@tonic-gate
2677c478bd9Sstevel@tonic-gate# common setup step -- create a testfile.conf
2687c478bd9Sstevel@tonic-gatesub set_testconffile {
2697c478bd9Sstevel@tonic-gate	my $fname = shift;
2707c478bd9Sstevel@tonic-gate	$fname = 'testfile.conf' unless defined($fname);
2717c478bd9Sstevel@tonic-gate
2727c478bd9Sstevel@tonic-gate	set_file($fname, <<'EOF');
2737c478bd9Sstevel@tonic-gate#
2747c478bd9Sstevel@tonic-gate# logadm.conf
2757c478bd9Sstevel@tonic-gate#
2767c478bd9Sstevel@tonic-gate# Default settings for system log file management.
277*bbf21555SRichard Lowe# The -w option to logadm(8) is the preferred way to write to this file,
2787c478bd9Sstevel@tonic-gate# but if you do edit it by hand, use "logadm -V" to check it for errors.
279d5dace52SMike Gerdts#
2807c478bd9Sstevel@tonic-gate# The format of lines in this file is:
2817c478bd9Sstevel@tonic-gate#       <logname> <options>
2827c478bd9Sstevel@tonic-gate# For each logname listed here, the default options to logadm
2837c478bd9Sstevel@tonic-gate# are given.  Options given on the logadm command line override
2847c478bd9Sstevel@tonic-gate# the defaults contained in this file.
2857c478bd9Sstevel@tonic-gate#
2867c478bd9Sstevel@tonic-gate# logadm typically runs early every morning via an entry in
2877c478bd9Sstevel@tonic-gate# root's crontab (see crontab(1)).
2887c478bd9Sstevel@tonic-gate#
289fdaa2824SBryan Cantrill/var/adm/messages -C 4 -P 'Thu Nov  1 16:56:42 2001' -a 'kill -HUP `cat /var/run/*syslog*pid`'
2907c478bd9Sstevel@tonic-gate/var/cron/log -s 512k -t /var/cron/olog
2917c478bd9Sstevel@tonic-gate/var/lp/logs/lpsched -C 2 -N -t '$file.$N'
2927c478bd9Sstevel@tonic-gate#
293*bbf21555SRichard Lowe# The entry below is used by turnacct(8)
2947c478bd9Sstevel@tonic-gate#
2957c478bd9Sstevel@tonic-gate/var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
2967c478bd9Sstevel@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'
297fdaa2824SBryan Cantrill/var/log/syslog -C 8 -P 'Thu Nov  1 09:16:38 2001' -a 'kill -HUP `cat /var/run/*syslog*pid`'
2987c478bd9Sstevel@tonic-gate/var/apache/logs/access_log -P 'Thu Nov  1 08:27:56 2001'
2997c478bd9Sstevel@tonic-gate/var/apache/logs/error_log -P 'Thu Nov  1 08:27:56 2001'
3007c478bd9Sstevel@tonic-gate/var/apache/logs/suexec_log -P 'Thu Nov  1 08:27:56 2001'
3017c478bd9Sstevel@tonic-gate/var/apache/logs/mod_jserv.log -P 'Thu Nov  1 08:27:56 2001'
3027c478bd9Sstevel@tonic-gate/var/apache/logs/jserv.log -P 'Thu Nov  1 08:27:56 2001'
3037c478bd9Sstevel@tonic-gateEOF
3047c478bd9Sstevel@tonic-gate}
3057c478bd9Sstevel@tonic-gate
3067c478bd9Sstevel@tonic-gate
3077c478bd9Sstevel@tonic-gate###########################################################################
3087c478bd9Sstevel@tonic-gate#
3097c478bd9Sstevel@tonic-gate#	conftest1 -- minimal basic test of the conf.c code
3107c478bd9Sstevel@tonic-gate#
3117c478bd9Sstevel@tonic-gate###########################################################################
3127c478bd9Sstevel@tonic-gatesub conftest1 {
3137c478bd9Sstevel@tonic-gate	set_testconffile;
3147c478bd9Sstevel@tonic-gate
3157c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
316e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
3177c478bd9Sstevel@tonic-gate/bin/sed '/^conffile <testfile.conf>:$/d' <std.out >sed.out
318e9a193fcSJohn.Zolnowsky@Sun.COMexec /bin/diff testfile.conf sed.out
3197c478bd9Sstevel@tonic-gateEOF
3207c478bd9Sstevel@tonic-gate
3217c478bd9Sstevel@tonic-gate	set_file('runtest', <<"EOF");
3227c478bd9Sstevel@tonic-gate# test "conftest1"
3237c478bd9Sstevel@tonic-gate$envsetup
3247c478bd9Sstevel@tonic-gateexec $bindir/conftest testfile.conf >std.out 2>std.err
3257c478bd9Sstevel@tonic-gateEOF
3267c478bd9Sstevel@tonic-gate}
3277c478bd9Sstevel@tonic-gate
3287c478bd9Sstevel@tonic-gate###########################################################################
3297c478bd9Sstevel@tonic-gate#
3307c478bd9Sstevel@tonic-gate#	conftest2 -- error path through conf.c
3317c478bd9Sstevel@tonic-gate#
3327c478bd9Sstevel@tonic-gate###########################################################################
3337c478bd9Sstevel@tonic-gatesub conftest2 {
3347c478bd9Sstevel@tonic-gate	set_file('testfile.conf', 'line fragment');
3357c478bd9Sstevel@tonic-gate
3367c478bd9Sstevel@tonic-gate	set_file('std.err.expect', <<'EOF');
337e9a193fcSJohn.Zolnowsky@Sun.COMconftest: Warning: file testfile.conf doesn't end with newline, last line ignored.
3387c478bd9Sstevel@tonic-gateEOF
3397c478bd9Sstevel@tonic-gate
3407c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
341e9a193fcSJohn.Zolnowsky@Sun.COMexec /bin/diff std.err.expect std.err
3427c478bd9Sstevel@tonic-gateEOF
3437c478bd9Sstevel@tonic-gate
3447c478bd9Sstevel@tonic-gate	set_file('runtest', <<"EOF");
3457c478bd9Sstevel@tonic-gate# test "conftest2"
3467c478bd9Sstevel@tonic-gate$envsetup
3477c478bd9Sstevel@tonic-gate$bindir/conftest testfile.conf >std.out 2>std.err || exit 0
3487c478bd9Sstevel@tonic-gateexit 1
3497c478bd9Sstevel@tonic-gateEOF
3507c478bd9Sstevel@tonic-gate}
3517c478bd9Sstevel@tonic-gate
3527c478bd9Sstevel@tonic-gate###########################################################################
3537c478bd9Sstevel@tonic-gate#
3547c478bd9Sstevel@tonic-gate#	globtest1 -- minimal basic test of the glob.c code
3557c478bd9Sstevel@tonic-gate#
3567c478bd9Sstevel@tonic-gate###########################################################################
3577c478bd9Sstevel@tonic-gatesub globtest1 {
3587c478bd9Sstevel@tonic-gate	set_file('fileBname12');
3597c478bd9Sstevel@tonic-gate	sleep 2;	# ensure above name is odler than below name
3607c478bd9Sstevel@tonic-gate	set_file('fileAname12');
3617c478bd9Sstevel@tonic-gate	set_file('fileAname1');
3627c478bd9Sstevel@tonic-gate	set_file('fileAname3');
3637c478bd9Sstevel@tonic-gate	set_file('fileAname5');
3647c478bd9Sstevel@tonic-gate	set_file('fileAname7');
3657c478bd9Sstevel@tonic-gate	set_file('fileAname9');
3667c478bd9Sstevel@tonic-gate	set_file('fileAname11');
3677c478bd9Sstevel@tonic-gate	set_file('fileBname0');
3687c478bd9Sstevel@tonic-gate	set_file('fileBname2');
3697c478bd9Sstevel@tonic-gate	set_file('fileBname4');
3707c478bd9Sstevel@tonic-gate	set_file('fileBname6');
3717c478bd9Sstevel@tonic-gate	set_file('fileBname8');
3727c478bd9Sstevel@tonic-gate	set_file('fileBname10');
3737c478bd9Sstevel@tonic-gate	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
3747c478bd9Sstevel@tonic-gate	mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
3757c478bd9Sstevel@tonic-gate	mkdir 'dir3', 0777 or die "mkdir dir3: $!\n";
3767c478bd9Sstevel@tonic-gate	mkdir 'dir1/dirA', 0777 or die "mkdir dir1/dirA: $!\n";
3777c478bd9Sstevel@tonic-gate	mkdir 'dir1/dirB', 0777 or die "mkdir dir1/dirB: $!\n";
3787c478bd9Sstevel@tonic-gate	mkdir 'dir1/dirC', 0777 or die "mkdir dir1/dirC: $!\n";
3797c478bd9Sstevel@tonic-gate	mkdir 'dir2/dirA', 0777 or die "mkdir dir2/dirA: $!\n";
3807c478bd9Sstevel@tonic-gate	mkdir 'dir2/dirB', 0777 or die "mkdir dir2/dirB: $!\n";
3817c478bd9Sstevel@tonic-gate	mkdir 'dir2/dirC', 0777 or die "mkdir dir2/dirC: $!\n";
3827c478bd9Sstevel@tonic-gate	set_file('dir1/fileAname1');
3837c478bd9Sstevel@tonic-gate	set_file('dir1/fileAname2');
3847c478bd9Sstevel@tonic-gate	set_file('dir1/fileAname3');
3857c478bd9Sstevel@tonic-gate	set_file('dir1/fileAname4');
3867c478bd9Sstevel@tonic-gate	set_file('dir1/fileAname5');
3877c478bd9Sstevel@tonic-gate	set_file('dir1/fileBname1');
3887c478bd9Sstevel@tonic-gate	set_file('dir1/fileBname2');
3897c478bd9Sstevel@tonic-gate	set_file('dir1/fileBname3');
3907c478bd9Sstevel@tonic-gate	set_file('dir1/fileBname4');
3917c478bd9Sstevel@tonic-gate	set_file('dir1/fileBname5');
3927c478bd9Sstevel@tonic-gate	# supply some varying sizes to produce different total size values
3937c478bd9Sstevel@tonic-gate	set_file('dir1/dirA/fileAname4', '4444');
3947c478bd9Sstevel@tonic-gate	sleep 2;	# ensure above file is oldest in dirA
3957c478bd9Sstevel@tonic-gate	set_file('dir1/dirA/fileAname1', '1');
3967c478bd9Sstevel@tonic-gate	set_file('dir1/dirA/fileAname2', '22');
3977c478bd9Sstevel@tonic-gate	set_file('dir1/dirA/fileAname3', '333');
3987c478bd9Sstevel@tonic-gate	set_file('dir1/dirA/fileAname5', '55555');
3997c478bd9Sstevel@tonic-gate	set_file('dir1/dirA/fileBname1', '1');
4007c478bd9Sstevel@tonic-gate	set_file('dir1/dirA/fileBname2', '22');
4017c478bd9Sstevel@tonic-gate	set_file('dir1/dirA/fileBname3', '333');
4027c478bd9Sstevel@tonic-gate	set_file('dir1/dirA/fileBname4', '4444');
4037c478bd9Sstevel@tonic-gate	set_file('dir1/dirA/fileBname5', '55555');
4047c478bd9Sstevel@tonic-gate	set_file('dir1/dirB/fileAname1', '1');
4057c478bd9Sstevel@tonic-gate	set_file('dir1/dirB/fileAname2', '22');
4067c478bd9Sstevel@tonic-gate	set_file('dir1/dirB/fileAname3', '333');
4077c478bd9Sstevel@tonic-gate	set_file('dir1/dirB/fileAname4', '4444');
4087c478bd9Sstevel@tonic-gate	set_file('dir1/dirB/fileAname5', '55555');
4097c478bd9Sstevel@tonic-gate	set_file('dir1/dirB/fileBname1', '1');
4107c478bd9Sstevel@tonic-gate	set_file('dir1/dirB/fileBname2', '22');
4117c478bd9Sstevel@tonic-gate	set_file('dir1/dirB/fileBname3', '333');
4127c478bd9Sstevel@tonic-gate	set_file('dir1/dirB/fileBname4', '4444');
4137c478bd9Sstevel@tonic-gate	set_file('dir1/dirB/fileBname5', '55555');
4147c478bd9Sstevel@tonic-gate	set_file('dir1/dirC/fileAname10', '12345678901');
4157c478bd9Sstevel@tonic-gate	set_file('dir1/dirC/fileAname20', '123456789022');
4167c478bd9Sstevel@tonic-gate	set_file('dir1/dirC/fileAname30', '1234567890333');
4177c478bd9Sstevel@tonic-gate	set_file('dir1/dirC/fileAname40', '12345678904444');
4187c478bd9Sstevel@tonic-gate	set_file('dir1/dirC/fileAname50', '123456789055555');
4197c478bd9Sstevel@tonic-gate	set_file('dir1/dirC/fileBname10', '12345678901');
4207c478bd9Sstevel@tonic-gate	set_file('dir1/dirC/fileBname20', '123456789022');
4217c478bd9Sstevel@tonic-gate	set_file('dir1/dirC/fileBname30', '1234567890333');
4227c478bd9Sstevel@tonic-gate	set_file('dir1/dirC/fileBname40', '12345678904444');
4237c478bd9Sstevel@tonic-gate	set_file('dir1/dirC/fileBname50', '123456789055555');
4247c478bd9Sstevel@tonic-gate
4257c478bd9Sstevel@tonic-gate	set_file('std.out.expect', <<'EOF');
4267c478bd9Sstevel@tonic-gate<file{A,B,C}name*>:
4277c478bd9Sstevel@tonic-gate    <./fileAname12>
4287c478bd9Sstevel@tonic-gate    <./fileAname1>
4297c478bd9Sstevel@tonic-gate    <./fileAname3>
4307c478bd9Sstevel@tonic-gate    <./fileAname5>
4317c478bd9Sstevel@tonic-gate    <./fileAname7>
4327c478bd9Sstevel@tonic-gate    <./fileAname9>
4337c478bd9Sstevel@tonic-gate    <./fileAname11>
4347c478bd9Sstevel@tonic-gate    <./fileBname12>
4357c478bd9Sstevel@tonic-gate    <./fileBname0>
4367c478bd9Sstevel@tonic-gate    <./fileBname2>
4377c478bd9Sstevel@tonic-gate    <./fileBname4>
4387c478bd9Sstevel@tonic-gate    <./fileBname6>
4397c478bd9Sstevel@tonic-gate    <./fileBname8>
4407c478bd9Sstevel@tonic-gate    <./fileBname10>
4417c478bd9Sstevel@tonic-gatetotal size: 0
4427c478bd9Sstevel@tonic-gate    oldest <./fileBname12>
4437c478bd9Sstevel@tonic-gate    oldest <./fileBname8>
4447c478bd9Sstevel@tonic-gate    oldest <./fileBname6>
4457c478bd9Sstevel@tonic-gate    oldest <./fileBname4>
4467c478bd9Sstevel@tonic-gate    oldest <./fileBname2>
4477c478bd9Sstevel@tonic-gate    oldest <./fileBname10>
4487c478bd9Sstevel@tonic-gate    oldest <./fileBname0>
4497c478bd9Sstevel@tonic-gate    oldest <./fileAname9>
4507c478bd9Sstevel@tonic-gate    oldest <./fileAname7>
4517c478bd9Sstevel@tonic-gate    oldest <./fileAname5>
4527c478bd9Sstevel@tonic-gate    oldest <./fileAname3>
4537c478bd9Sstevel@tonic-gate    oldest <./fileAname12>
4547c478bd9Sstevel@tonic-gate    oldest <./fileAname11>
4557c478bd9Sstevel@tonic-gate    oldest <./fileAname1>
4567c478bd9Sstevel@tonic-gate<file{A,B,C}name>:
4577c478bd9Sstevel@tonic-gate    <fileAname>
4587c478bd9Sstevel@tonic-gate    <fileBname>
4597c478bd9Sstevel@tonic-gate    <fileCname>
4607c478bd9Sstevel@tonic-gatetotal size: 0
4617c478bd9Sstevel@tonic-gate    oldest <fileCname>
4627c478bd9Sstevel@tonic-gate    oldest <fileBname>
4637c478bd9Sstevel@tonic-gate    oldest <fileAname>
4647c478bd9Sstevel@tonic-gate<dir1/dirA/file*>:
4657c478bd9Sstevel@tonic-gate    <./dir1/dirA/fileAname4>
4667c478bd9Sstevel@tonic-gate    <./dir1/dirA/fileAname1>
4677c478bd9Sstevel@tonic-gate    <./dir1/dirA/fileAname2>
4687c478bd9Sstevel@tonic-gate    <./dir1/dirA/fileAname3>
4697c478bd9Sstevel@tonic-gate    <./dir1/dirA/fileAname5>
4707c478bd9Sstevel@tonic-gate    <./dir1/dirA/fileBname1>
4717c478bd9Sstevel@tonic-gate    <./dir1/dirA/fileBname2>
4727c478bd9Sstevel@tonic-gate    <./dir1/dirA/fileBname3>
4737c478bd9Sstevel@tonic-gate    <./dir1/dirA/fileBname4>
4747c478bd9Sstevel@tonic-gate    <./dir1/dirA/fileBname5>
4757c478bd9Sstevel@tonic-gatetotal size: 30
4767c478bd9Sstevel@tonic-gate    oldest <./dir1/dirA/fileAname4>
4777c478bd9Sstevel@tonic-gate    oldest <./dir1/dirA/fileBname5>
4787c478bd9Sstevel@tonic-gate    oldest <./dir1/dirA/fileBname4>
4797c478bd9Sstevel@tonic-gate    oldest <./dir1/dirA/fileBname3>
4807c478bd9Sstevel@tonic-gate    oldest <./dir1/dirA/fileBname2>
4817c478bd9Sstevel@tonic-gate    oldest <./dir1/dirA/fileBname1>
4827c478bd9Sstevel@tonic-gate    oldest <./dir1/dirA/fileAname5>
4837c478bd9Sstevel@tonic-gate    oldest <./dir1/dirA/fileAname3>
4847c478bd9Sstevel@tonic-gate    oldest <./dir1/dirA/fileAname2>
4857c478bd9Sstevel@tonic-gate    oldest <./dir1/dirA/fileAname1>
4867c478bd9Sstevel@tonic-gate<dir[13]/[e-z]*>:
4877c478bd9Sstevel@tonic-gate    <./dir1/fileAname1>
4887c478bd9Sstevel@tonic-gate    <./dir1/fileAname2>
4897c478bd9Sstevel@tonic-gate    <./dir1/fileAname3>
4907c478bd9Sstevel@tonic-gate    <./dir1/fileAname4>
4917c478bd9Sstevel@tonic-gate    <./dir1/fileAname5>
4927c478bd9Sstevel@tonic-gate    <./dir1/fileBname1>
4937c478bd9Sstevel@tonic-gate    <./dir1/fileBname2>
4947c478bd9Sstevel@tonic-gate    <./dir1/fileBname3>
4957c478bd9Sstevel@tonic-gate    <./dir1/fileBname4>
4967c478bd9Sstevel@tonic-gate    <./dir1/fileBname5>
4977c478bd9Sstevel@tonic-gatetotal size: 0
4987c478bd9Sstevel@tonic-gate    oldest <./dir1/fileBname5>
4997c478bd9Sstevel@tonic-gate    oldest <./dir1/fileBname4>
5007c478bd9Sstevel@tonic-gate    oldest <./dir1/fileBname3>
5017c478bd9Sstevel@tonic-gate    oldest <./dir1/fileBname2>
5027c478bd9Sstevel@tonic-gate    oldest <./dir1/fileBname1>
5037c478bd9Sstevel@tonic-gate    oldest <./dir1/fileAname5>
5047c478bd9Sstevel@tonic-gate    oldest <./dir1/fileAname4>
5057c478bd9Sstevel@tonic-gate    oldest <./dir1/fileAname3>
5067c478bd9Sstevel@tonic-gate    oldest <./dir1/fileAname2>
5077c478bd9Sstevel@tonic-gate    oldest <./dir1/fileAname1>
5087c478bd9Sstevel@tonic-gate<dir?/dir[AC]/fileBname[2-9]>:
5097c478bd9Sstevel@tonic-gate    <./dir1/dirA/fileBname2>
5107c478bd9Sstevel@tonic-gate    <./dir1/dirA/fileBname3>
5117c478bd9Sstevel@tonic-gate    <./dir1/dirA/fileBname4>
5127c478bd9Sstevel@tonic-gate    <./dir1/dirA/fileBname5>
5137c478bd9Sstevel@tonic-gatetotal size: 14
5147c478bd9Sstevel@tonic-gate    oldest <./dir1/dirA/fileBname5>
5157c478bd9Sstevel@tonic-gate    oldest <./dir1/dirA/fileBname4>
5167c478bd9Sstevel@tonic-gate    oldest <./dir1/dirA/fileBname3>
5177c478bd9Sstevel@tonic-gate    oldest <./dir1/dirA/fileBname2>
5187c478bd9Sstevel@tonic-gate<file[A-Z]n.*e([0-9]+)$0>:
5197c478bd9Sstevel@tonic-gate    <./fileBname12>
5207c478bd9Sstevel@tonic-gate    <./fileAname12>
5217c478bd9Sstevel@tonic-gate    <./fileAname1>
5227c478bd9Sstevel@tonic-gate    <./fileAname3>
5237c478bd9Sstevel@tonic-gate    <./fileAname5>
5247c478bd9Sstevel@tonic-gate    <./fileAname7>
5257c478bd9Sstevel@tonic-gate    <./fileAname9>
5267c478bd9Sstevel@tonic-gate    <./fileAname11>
5277c478bd9Sstevel@tonic-gate    <./fileBname0>
5287c478bd9Sstevel@tonic-gate    <./fileBname2>
5297c478bd9Sstevel@tonic-gate    <./fileBname4>
5307c478bd9Sstevel@tonic-gate    <./fileBname6>
5317c478bd9Sstevel@tonic-gate    <./fileBname8>
5327c478bd9Sstevel@tonic-gate    <./fileBname10>
5337c478bd9Sstevel@tonic-gatetotal size: 0
5347c478bd9Sstevel@tonic-gate    oldest <./fileBname12>
5357c478bd9Sstevel@tonic-gate    oldest <./fileAname12>
5367c478bd9Sstevel@tonic-gate    oldest <./fileAname11>
5377c478bd9Sstevel@tonic-gate    oldest <./fileBname10>
5387c478bd9Sstevel@tonic-gate    oldest <./fileAname9>
5397c478bd9Sstevel@tonic-gate    oldest <./fileBname8>
5407c478bd9Sstevel@tonic-gate    oldest <./fileAname7>
5417c478bd9Sstevel@tonic-gate    oldest <./fileBname6>
5427c478bd9Sstevel@tonic-gate    oldest <./fileAname5>
5437c478bd9Sstevel@tonic-gate    oldest <./fileBname4>
5447c478bd9Sstevel@tonic-gate    oldest <./fileAname3>
5457c478bd9Sstevel@tonic-gate    oldest <./fileBname2>
5467c478bd9Sstevel@tonic-gate    oldest <./fileAname1>
5477c478bd9Sstevel@tonic-gate    oldest <./fileBname0>
5487c478bd9Sstevel@tonic-gateEOF
5497c478bd9Sstevel@tonic-gate
5507c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
551e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
552e9a193fcSJohn.Zolnowsky@Sun.COMexec /bin/diff std.out.expect std.out
5537c478bd9Sstevel@tonic-gateEOF
5547c478bd9Sstevel@tonic-gate
5557c478bd9Sstevel@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\'';
5567c478bd9Sstevel@tonic-gate
5577c478bd9Sstevel@tonic-gate	set_file('runtest', <<"EOF");
5587c478bd9Sstevel@tonic-gate# test "globtest1"
5597c478bd9Sstevel@tonic-gate$envsetup
5607c478bd9Sstevel@tonic-gateexec $bindir/globtest $testglobs >std.out 2>std.err
5617c478bd9Sstevel@tonic-gateEOF
5627c478bd9Sstevel@tonic-gate}
5637c478bd9Sstevel@tonic-gate
5647c478bd9Sstevel@tonic-gate###########################################################################
5657c478bd9Sstevel@tonic-gate#
5667c478bd9Sstevel@tonic-gate#	globtest2 -- error path through glob.c
5677c478bd9Sstevel@tonic-gate#
5687c478bd9Sstevel@tonic-gate###########################################################################
5697c478bd9Sstevel@tonic-gatesub globtest2 {
5707c478bd9Sstevel@tonic-gate	set_file('std.err.expect', <<'EOF');
5717c478bd9Sstevel@tonic-gateglobtest: Error: Missing }
5727c478bd9Sstevel@tonic-gateEOF
5737c478bd9Sstevel@tonic-gate
5747c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
575e9a193fcSJohn.Zolnowsky@Sun.COMexec /bin/diff std.err.expect std.err
5767c478bd9Sstevel@tonic-gateEOF
5777c478bd9Sstevel@tonic-gate
5787c478bd9Sstevel@tonic-gate	set_file('runtest', <<"EOF");
5797c478bd9Sstevel@tonic-gate# test "globtest2"
5807c478bd9Sstevel@tonic-gate$envsetup
5817c478bd9Sstevel@tonic-gate$bindir/globtest 'hello{there' >std.out 2>std.err || exit 0
5827c478bd9Sstevel@tonic-gateexit 1
5837c478bd9Sstevel@tonic-gateEOF
5847c478bd9Sstevel@tonic-gate}
5857c478bd9Sstevel@tonic-gate
5867c478bd9Sstevel@tonic-gate###########################################################################
5877c478bd9Sstevel@tonic-gate#
5887c478bd9Sstevel@tonic-gate#	kwtest1 -- minimal basic test of the kw.c code
5897c478bd9Sstevel@tonic-gate#
5907c478bd9Sstevel@tonic-gate###########################################################################
5917c478bd9Sstevel@tonic-gatesub kwtest1 {
5927c478bd9Sstevel@tonic-gate	$domainname = `/bin/domainname`; chomp $domainname;
5937c478bd9Sstevel@tonic-gate	$isa = `/bin/uname -p`; chomp $isa;
5947c478bd9Sstevel@tonic-gate	$platform = `/bin/uname -i`; chomp $platform;
5957c478bd9Sstevel@tonic-gate	$nodename = `/bin/uname -n`; chomp $nodename;
5967c478bd9Sstevel@tonic-gate	$machine = `/bin/uname -m`; chomp $machine;
5977c478bd9Sstevel@tonic-gate	$release = `/bin/uname -r`; chomp $release;
5983010f05bSdp	# /bin/zonename is in SUNWzoneu and so may not be present
5993010f05bSdp	if (-f "/bin/zonename") {
6003010f05bSdp		$zonename = `/bin/zonename`; chomp $zonename;
6013010f05bSdp	} else {
6023010f05bSdp		$zonename = "global";
6033010f05bSdp	}
6047c478bd9Sstevel@tonic-gate$secondblob=<<'EOF';
6057c478bd9Sstevel@tonic-gateexpand<$file.$n> n -1 hasn 1 result </var/log/syslog\.([0-9]+)$0>
6067c478bd9Sstevel@tonic-gateexpand<$file.$n> n 0 hasn 1 result </var/log/syslog.0>
6077c478bd9Sstevel@tonic-gateexpand<$file.$n> n 1 hasn 1 result </var/log/syslog.1>
6087c478bd9Sstevel@tonic-gateexpand<moose%d.$n> n -1 hasn 1 result <moose[0-9]+\.([0-9]+)$0>
6097c478bd9Sstevel@tonic-gateexpand<moose%d.$n> n 0 hasn 1 result <moose%d.0>
6107c478bd9Sstevel@tonic-gateexpand<moose%d.$n> n 1 hasn 1 result <moose%d.1>
6117c478bd9Sstevel@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>
6127c478bd9Sstevel@tonic-gateexpand</var/logs-%Y/moose-$isa$#porklips%d.$n> n 0 hasn 1 result </var/logs-%Y/moose-ISAporklips%d.0>
6137c478bd9Sstevel@tonic-gateexpand</var/logs-%Y/moose-$isa$#porklips%d.$n> n 1 hasn 1 result </var/logs-%Y/moose-ISAporklips%d.1>
6147c478bd9Sstevel@tonic-gateEOF
6157c478bd9Sstevel@tonic-gate	$percentd = `/bin/env TZ=UTC /bin/date +%d`; chomp $percentd;
6167c478bd9Sstevel@tonic-gate	$percentY = `/bin/env TZ=UTC /bin/date +%Y`; chomp $percentY;
6177c478bd9Sstevel@tonic-gate	$secondblob =~ s/%d/$percentd/mg;
6187c478bd9Sstevel@tonic-gate	$secondblob =~ s/%Y/$percentY/mg;
6197c478bd9Sstevel@tonic-gate	$secondblob =~ s/ISA/$isa/mg;
620636deb66Sgm	$utcenv = "TZ=UTC export TZ";
6217c478bd9Sstevel@tonic-gate	chomp $secondblob;
6227c478bd9Sstevel@tonic-gate	set_file('sed.out.expect', <<"EOF");
6237c478bd9Sstevel@tonic-gate            basename syslog
6247c478bd9Sstevel@tonic-gate             dirname /var/log
6257c478bd9Sstevel@tonic-gate              domain $domainname
6267c478bd9Sstevel@tonic-gate                file /var/log/syslog
6277c478bd9Sstevel@tonic-gate                home $dir
6287c478bd9Sstevel@tonic-gate                 isa $isa
6297c478bd9Sstevel@tonic-gate             logname $ENV{LOGNAME}
6307c478bd9Sstevel@tonic-gate             machine $machine
6317c478bd9Sstevel@tonic-gate               nfile
6327c478bd9Sstevel@tonic-gate            nodename $nodename
6337c478bd9Sstevel@tonic-gate            platform $platform
6347c478bd9Sstevel@tonic-gate             release $release
6357c478bd9Sstevel@tonic-gate                user $ENV{USER}
6363010f05bSdp            zonename $zonename
6377c478bd9Sstevel@tonic-gate$secondblob
6387c478bd9Sstevel@tonic-gateEOF
6397c478bd9Sstevel@tonic-gate
6407c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
641e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
6427c478bd9Sstevel@tonic-gate/bin/sed -e '/^ *secs [0-9][0-9]*$/d'\
6437c478bd9Sstevel@tonic-gate	-e "s/%d/`/bin/env TZ=UTC /bin/date +%d`/g"\
6447c478bd9Sstevel@tonic-gate	-e "s/%Y/`/bin/env TZ=UTC /bin/date +%Y`/g"\
6457c478bd9Sstevel@tonic-gate	<std.out >sed.out
646e9a193fcSJohn.Zolnowsky@Sun.COMexec /bin/diff sed.out.expect sed.out
6477c478bd9Sstevel@tonic-gateEOF
6487c478bd9Sstevel@tonic-gate
6497c478bd9Sstevel@tonic-gate	$kwtest='kwtest /var/log/syslog \'$file.$n\' \'moose%d.$n\' \'/var/logs-%Y/moose-$isa$#porklips%d.$n\'';
6507c478bd9Sstevel@tonic-gate	set_file('runtest', <<"EOF");
6517c478bd9Sstevel@tonic-gate# test "kwtest1"
6527c478bd9Sstevel@tonic-gate$envsetup
653636deb66Sgm$utcenv
6547c478bd9Sstevel@tonic-gateexec $bindir/$kwtest >std.out 2>std.err
6557c478bd9Sstevel@tonic-gateEOF
6567c478bd9Sstevel@tonic-gate}
6577c478bd9Sstevel@tonic-gate
6587c478bd9Sstevel@tonic-gate###########################################################################
6597c478bd9Sstevel@tonic-gate#
6607c478bd9Sstevel@tonic-gate#	kwtest2 -- NULL environment variables test of the kw.c code
6617c478bd9Sstevel@tonic-gate#
6627c478bd9Sstevel@tonic-gate###########################################################################
6637c478bd9Sstevel@tonic-gatesub kwtest2 {
6647c478bd9Sstevel@tonic-gate	$domainname = `/bin/domainname`; chomp $domainname;
6657c478bd9Sstevel@tonic-gate	$isa = `/bin/uname -p`; chomp $isa;
6667c478bd9Sstevel@tonic-gate	$platform = `/bin/uname -i`; chomp $platform;
6677c478bd9Sstevel@tonic-gate	$nodename = `/bin/uname -n`; chomp $nodename;
6687c478bd9Sstevel@tonic-gate	$machine = `/bin/uname -m`; chomp $machine;
6697c478bd9Sstevel@tonic-gate	$release = `/bin/uname -r`; chomp $release;
6703010f05bSdp	# /bin/zonename is in SUNWzoneu and so may not be present
6713010f05bSdp	if (-f "/bin/zonename") {
6723010f05bSdp		$zonename = `/bin/zonename`; chomp $zonename;
6733010f05bSdp	} else {
6743010f05bSdp		$zonename = "global";
6753010f05bSdp	}
6767c478bd9Sstevel@tonic-gate$secondblob=<<'EOF';
6777c478bd9Sstevel@tonic-gateexpand<$file.$n> n -1 hasn 1 result </var/log/syslog\.([0-9]+)$0>
6787c478bd9Sstevel@tonic-gateexpand<$file.$n> n 0 hasn 1 result </var/log/syslog.0>
6797c478bd9Sstevel@tonic-gateexpand<$file.$n> n 1 hasn 1 result </var/log/syslog.1>
6807c478bd9Sstevel@tonic-gateexpand<moose%d.$n> n -1 hasn 1 result <moose[0-9]+\.([0-9]+)$0>
6817c478bd9Sstevel@tonic-gateexpand<moose%d.$n> n 0 hasn 1 result <moose%d.0>
6827c478bd9Sstevel@tonic-gateexpand<moose%d.$n> n 1 hasn 1 result <moose%d.1>
6837c478bd9Sstevel@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>
6847c478bd9Sstevel@tonic-gateexpand</var/logs-%Y/moose-$isa$#porklips%d.$n> n 0 hasn 1 result </var/logs-%Y/moose-ISAporklips%d.0>
6857c478bd9Sstevel@tonic-gateexpand</var/logs-%Y/moose-$isa$#porklips%d.$n> n 1 hasn 1 result </var/logs-%Y/moose-ISAporklips%d.1>
6867c478bd9Sstevel@tonic-gateEOF
6877c478bd9Sstevel@tonic-gate	$percentd = `/bin/env TZ=UTC /bin/date +%d`; chomp $percentd;
6887c478bd9Sstevel@tonic-gate	$percentY = `/bin/env TZ=UTC /bin/date +%Y`; chomp $percentY;
6897c478bd9Sstevel@tonic-gate	$secondblob =~ s/%d/$percentd/mg;
6907c478bd9Sstevel@tonic-gate	$secondblob =~ s/%Y/$percentY/mg;
6917c478bd9Sstevel@tonic-gate	$secondblob =~ s/ISA/$isa/mg;
6927c478bd9Sstevel@tonic-gate	chomp $secondblob;
6937c478bd9Sstevel@tonic-gate	set_file('sed.out.expect', <<"EOF");
6947c478bd9Sstevel@tonic-gate            basename syslog
6957c478bd9Sstevel@tonic-gate             dirname /var/log
6967c478bd9Sstevel@tonic-gate              domain $domainname
6977c478bd9Sstevel@tonic-gate                file /var/log/syslog
6987c478bd9Sstevel@tonic-gate                home
6997c478bd9Sstevel@tonic-gate                 isa $isa
7007c478bd9Sstevel@tonic-gate             logname
7017c478bd9Sstevel@tonic-gate             machine $machine
7027c478bd9Sstevel@tonic-gate               nfile
7037c478bd9Sstevel@tonic-gate            nodename $nodename
7047c478bd9Sstevel@tonic-gate            platform $platform
7057c478bd9Sstevel@tonic-gate             release $release
7067c478bd9Sstevel@tonic-gate                user
7073010f05bSdp            zonename $zonename
7087c478bd9Sstevel@tonic-gate$secondblob
7097c478bd9Sstevel@tonic-gateEOF
7107c478bd9Sstevel@tonic-gate
7117c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
712e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
7137c478bd9Sstevel@tonic-gate/bin/sed -e '/^ *secs [0-9][0-9]*$/d'\
7147c478bd9Sstevel@tonic-gate	-e "s/%d/`/bin/env TZ=UTC /bin/date +%d`/g"\
7157c478bd9Sstevel@tonic-gate	-e "s/%Y/`/bin/env TZ=UTC /bin/date +%Y`/g"\
7167c478bd9Sstevel@tonic-gate	<std.out >sed.out
717e9a193fcSJohn.Zolnowsky@Sun.COMexec /bin/diff sed.out.expect sed.out
7187c478bd9Sstevel@tonic-gateEOF
7197c478bd9Sstevel@tonic-gate
7207c478bd9Sstevel@tonic-gate	$kwtest='kwtest /var/log/syslog \'$file.$n\' \'moose%d.$n\' \'/var/logs-%Y/moose-$isa$#porklips%d.$n\'';
7217c478bd9Sstevel@tonic-gate	set_file('runtest', <<"EOF");
7227c478bd9Sstevel@tonic-gate# test "kwtest2"
7237c478bd9Sstevel@tonic-gate$envsetup
7247c478bd9Sstevel@tonic-gateLOGNAME=
7257c478bd9Sstevel@tonic-gateexport LOGNAME
7267c478bd9Sstevel@tonic-gateHOME=
7277c478bd9Sstevel@tonic-gateexport HOME
7287c478bd9Sstevel@tonic-gateUSER=
7297c478bd9Sstevel@tonic-gateexport USER
730e9a193fcSJohn.Zolnowsky@Sun.COMTZ=UTC
731e9a193fcSJohn.Zolnowsky@Sun.COMexport TZ
7327c478bd9Sstevel@tonic-gateexec $bindir/$kwtest >std.out 2>std.err
7337c478bd9Sstevel@tonic-gateEOF
7347c478bd9Sstevel@tonic-gate}
7357c478bd9Sstevel@tonic-gate
7367c478bd9Sstevel@tonic-gate###########################################################################
7377c478bd9Sstevel@tonic-gate#
7387c478bd9Sstevel@tonic-gate#	luttest1 -- minimal basic test of the lut.c code
7397c478bd9Sstevel@tonic-gate#
7407c478bd9Sstevel@tonic-gate###########################################################################
7417c478bd9Sstevel@tonic-gatesub luttest1 {
7427c478bd9Sstevel@tonic-gate	set_file('std.out.expect', <<'EOF');
7437c478bd9Sstevel@tonic-gatelut contains:
7447c478bd9Sstevel@tonic-gate<fix> <NULL> (<NULL>)
7457c478bd9Sstevel@tonic-gate<one> <two> (<two>)
7467c478bd9Sstevel@tonic-gate<seven> <eight> (<eight>)
7477c478bd9Sstevel@tonic-gate<six> <NULL> (<NULL>)
7487c478bd9Sstevel@tonic-gate<three> <four> (<four>)
7497c478bd9Sstevel@tonic-gatedup lut contains:
7507c478bd9Sstevel@tonic-gate<fix> <NULL> (<NULL>)
7517c478bd9Sstevel@tonic-gate<one> <two> (<two>)
7527c478bd9Sstevel@tonic-gate<seven> <eight> (<eight>)
7537c478bd9Sstevel@tonic-gate<six> <NULL> (<NULL>)
7547c478bd9Sstevel@tonic-gate<three> <four> (<four>)
7557c478bd9Sstevel@tonic-gateEOF
7567c478bd9Sstevel@tonic-gate
7577c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
758e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
759e9a193fcSJohn.Zolnowsky@Sun.COMexec /bin/diff std.out.expect std.out
7607c478bd9Sstevel@tonic-gateEOF
7617c478bd9Sstevel@tonic-gate
7627c478bd9Sstevel@tonic-gate	set_file('runtest', <<"EOF");
7637c478bd9Sstevel@tonic-gate# test "luttest1"
7647c478bd9Sstevel@tonic-gate$envsetup
7657c478bd9Sstevel@tonic-gateexec $bindir/luttest one=two three=four fix six seven=eight >std.out 2>std.err
7667c478bd9Sstevel@tonic-gateEOF
7677c478bd9Sstevel@tonic-gate}
7687c478bd9Sstevel@tonic-gate
7697c478bd9Sstevel@tonic-gate###########################################################################
7707c478bd9Sstevel@tonic-gate#
7717c478bd9Sstevel@tonic-gate#	optstest1 -- minimal basic test of the opts.c code
7727c478bd9Sstevel@tonic-gate#
7737c478bd9Sstevel@tonic-gate###########################################################################
7747c478bd9Sstevel@tonic-gatesub optstest1 {
7757c478bd9Sstevel@tonic-gate	$options="-a -b moose -c 1h -d 'Fri Nov  2 13:19:55 2001' -e 1k -f 2 one two three";
7767c478bd9Sstevel@tonic-gate	set_file('std.out.expect', <<"EOF");
7777c478bd9Sstevel@tonic-gateoptions: $options
7787c478bd9Sstevel@tonic-gateEOF
7797c478bd9Sstevel@tonic-gate
7807c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
781e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
782e9a193fcSJohn.Zolnowsky@Sun.COMexec /bin/diff std.out.expect std.out
7837c478bd9Sstevel@tonic-gateEOF
7847c478bd9Sstevel@tonic-gate
7857c478bd9Sstevel@tonic-gate	set_file('runtest', <<"EOF");
7867c478bd9Sstevel@tonic-gate# test "optstest1"
7877c478bd9Sstevel@tonic-gate$envsetup
7887c478bd9Sstevel@tonic-gateexec $bindir/optstest $options >std.out 2>std.err
7897c478bd9Sstevel@tonic-gateEOF
7907c478bd9Sstevel@tonic-gate}
7917c478bd9Sstevel@tonic-gate
7927c478bd9Sstevel@tonic-gate###########################################################################
7937c478bd9Sstevel@tonic-gate#
7947c478bd9Sstevel@tonic-gate#	optstest2 -- error path through opts.c code
7957c478bd9Sstevel@tonic-gate#
7967c478bd9Sstevel@tonic-gate###########################################################################
7977c478bd9Sstevel@tonic-gatesub optstest2 {
7987c478bd9Sstevel@tonic-gate	$options="-a -b -c 1h -d 'Fri Nov  2 13:19:55 2001' -e 1k -f 2 one two three";
7997c478bd9Sstevel@tonic-gate	set_file('std.err.expect', <<'EOF');
8007c478bd9Sstevel@tonic-gateoptstest: Error: Option 'b' requires an argument
8017c478bd9Sstevel@tonic-gateoptstest: Error: opts parsing failed
8027c478bd9Sstevel@tonic-gateEOF
8037c478bd9Sstevel@tonic-gate
8047c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
8057c478bd9Sstevel@tonic-gate[ -s std.out ] && exit 1
806e9a193fcSJohn.Zolnowsky@Sun.COMexec /bin/diff std.err.expect std.err
8077c478bd9Sstevel@tonic-gateEOF
8087c478bd9Sstevel@tonic-gate
8097c478bd9Sstevel@tonic-gate	set_file('runtest', <<"EOF");
8107c478bd9Sstevel@tonic-gate# test "optstest2"
8117c478bd9Sstevel@tonic-gate$envsetup
8127c478bd9Sstevel@tonic-gate$bindir/optstest $options >std.out 2>std.err || exit 0
8137c478bd9Sstevel@tonic-gateexit 1
8147c478bd9Sstevel@tonic-gateEOF
8157c478bd9Sstevel@tonic-gate}
8167c478bd9Sstevel@tonic-gate
8177c478bd9Sstevel@tonic-gate###########################################################################
8187c478bd9Sstevel@tonic-gate#
8197c478bd9Sstevel@tonic-gate#	logadmV1 -- test of "logadm -V"
8207c478bd9Sstevel@tonic-gate#
8217c478bd9Sstevel@tonic-gate###########################################################################
8227c478bd9Sstevel@tonic-gatesub logadmV1 {
8237c478bd9Sstevel@tonic-gate	set_testconffile;
8247c478bd9Sstevel@tonic-gate
8257c478bd9Sstevel@tonic-gate	set_file('std.out.expect', <<'EOF');
826fdaa2824SBryan Cantrill/var/adm/messages -C 4 -P 'Thu Nov  1 16:56:42 2001' -a 'kill -HUP `cat /var/run/*syslog*pid`'
8277c478bd9Sstevel@tonic-gate/var/cron/log -s 512k -t /var/cron/olog
8287c478bd9Sstevel@tonic-gate/var/lp/logs/lpsched -C 2 -N -t '$file.$N'
8297c478bd9Sstevel@tonic-gate/var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
8307c478bd9Sstevel@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'
831fdaa2824SBryan Cantrill/var/log/syslog -C 8 -P 'Thu Nov  1 09:16:38 2001' -a 'kill -HUP `cat /var/run/*syslog*pid`'
8327c478bd9Sstevel@tonic-gate/var/apache/logs/access_log -P 'Thu Nov  1 08:27:56 2001'
8337c478bd9Sstevel@tonic-gate/var/apache/logs/error_log -P 'Thu Nov  1 08:27:56 2001'
8347c478bd9Sstevel@tonic-gate/var/apache/logs/suexec_log -P 'Thu Nov  1 08:27:56 2001'
8357c478bd9Sstevel@tonic-gate/var/apache/logs/mod_jserv.log -P 'Thu Nov  1 08:27:56 2001'
8367c478bd9Sstevel@tonic-gate/var/apache/logs/jserv.log -P 'Thu Nov  1 08:27:56 2001'
8377c478bd9Sstevel@tonic-gateEOF
8387c478bd9Sstevel@tonic-gate
8397c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
840e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
841e9a193fcSJohn.Zolnowsky@Sun.COMexec /bin/diff std.out.expect std.out
8427c478bd9Sstevel@tonic-gateEOF
8437c478bd9Sstevel@tonic-gate
8447c478bd9Sstevel@tonic-gate	set_file('runtest', <<"EOF");
8457c478bd9Sstevel@tonic-gate# test "logadmV1"
8467c478bd9Sstevel@tonic-gate$envsetup
847e9a193fcSJohn.Zolnowsky@Sun.COMexec $bindir/logadm -f testfile.conf -F testfile.conf -V >std.out 2>std.err
8487c478bd9Sstevel@tonic-gateEOF
8497c478bd9Sstevel@tonic-gate}
8507c478bd9Sstevel@tonic-gate
8517c478bd9Sstevel@tonic-gate###########################################################################
8527c478bd9Sstevel@tonic-gate#
8537c478bd9Sstevel@tonic-gate#	logadmV2 -- test of "logadm -V <entry>"
8547c478bd9Sstevel@tonic-gate#
8557c478bd9Sstevel@tonic-gate###########################################################################
8567c478bd9Sstevel@tonic-gatesub logadmV2 {
8577c478bd9Sstevel@tonic-gate	set_testconffile;
8587c478bd9Sstevel@tonic-gate
8597c478bd9Sstevel@tonic-gate	set_file('std.out.expect', <<'EOF');
8607c478bd9Sstevel@tonic-gate/var/cron/log -s 512k -t /var/cron/olog
8617c478bd9Sstevel@tonic-gate/var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
8627c478bd9Sstevel@tonic-gateEOF
8637c478bd9Sstevel@tonic-gate
8647c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
865e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
866e9a193fcSJohn.Zolnowsky@Sun.COMexec /bin/diff std.out.expect std.out
8677c478bd9Sstevel@tonic-gateEOF
8687c478bd9Sstevel@tonic-gate
8697c478bd9Sstevel@tonic-gate	set_file('runtest', <<"EOF");
8707c478bd9Sstevel@tonic-gate# test "logadmV2"
8717c478bd9Sstevel@tonic-gate$envsetup
872e9a193fcSJohn.Zolnowsky@Sun.COMexec $bindir/logadm -f testfile.conf -F testfile.conf -V /var/cron/log /var/adm/pacct >std.out 2>std.err
8737c478bd9Sstevel@tonic-gateEOF
8747c478bd9Sstevel@tonic-gate}
8757c478bd9Sstevel@tonic-gate
8767c478bd9Sstevel@tonic-gate###########################################################################
8777c478bd9Sstevel@tonic-gate#
8787c478bd9Sstevel@tonic-gate#	logadmr -- test of "logadm -r <entry>"
8797c478bd9Sstevel@tonic-gate#
8807c478bd9Sstevel@tonic-gate###########################################################################
8817c478bd9Sstevel@tonic-gatesub logadmr {
8827c478bd9Sstevel@tonic-gate	set_testconffile;
8837c478bd9Sstevel@tonic-gate	set_testconffile('testfile.conf.orig');
8847c478bd9Sstevel@tonic-gate
8857c478bd9Sstevel@tonic-gate	set_file('diff.out.expect', <<'EOF');
886e9a193fcSJohn.Zolnowsky@Sun.COM18d17
887e9a193fcSJohn.Zolnowsky@Sun.COM< /var/cron/log -s 512k -t /var/cron/olog
888e9a193fcSJohn.Zolnowsky@Sun.COM23d21
889e9a193fcSJohn.Zolnowsky@Sun.COM< /var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
8907c478bd9Sstevel@tonic-gateEOF
8917c478bd9Sstevel@tonic-gate
8927c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
893e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
894e9a193fcSJohn.Zolnowsky@Sun.COM/bin/diff testfile.conf.orig testfile.conf > diff.out
895e9a193fcSJohn.Zolnowsky@Sun.COMexec /bin/diff diff.out.expect diff.out
8967c478bd9Sstevel@tonic-gateEOF
8977c478bd9Sstevel@tonic-gate
8987c478bd9Sstevel@tonic-gate	set_file('runtest', <<"EOF");
8997c478bd9Sstevel@tonic-gate# test "logadmr"
9007c478bd9Sstevel@tonic-gate$envsetup
901e9a193fcSJohn.Zolnowsky@Sun.COMexec $bindir/logadm -f testfile.conf -F testfile.conf -r /var/cron/log /var/adm/pacct >std.out 2>std.err
9027c478bd9Sstevel@tonic-gateEOF
9037c478bd9Sstevel@tonic-gate}
9047c478bd9Sstevel@tonic-gate
9057c478bd9Sstevel@tonic-gate###########################################################################
9067c478bd9Sstevel@tonic-gate#
9077c478bd9Sstevel@tonic-gate#	logadmw -- test of "logadm -w <entry>"
9087c478bd9Sstevel@tonic-gate#
9097c478bd9Sstevel@tonic-gate###########################################################################
9107c478bd9Sstevel@tonic-gatesub logadmw {
9117c478bd9Sstevel@tonic-gate	set_testconffile;
9127c478bd9Sstevel@tonic-gate	set_testconffile('testfile.conf.orig');
9137c478bd9Sstevel@tonic-gate
9147c478bd9Sstevel@tonic-gate	set_file('diff.out.expect', <<'EOF');
915e9a193fcSJohn.Zolnowsky@Sun.COM30a31
916e9a193fcSJohn.Zolnowsky@Sun.COM> moose -C 20 -a moose_after_cmd -g pig -m 664 -o cow -p never /moose/file
9177c478bd9Sstevel@tonic-gateEOF
9187c478bd9Sstevel@tonic-gate
9197c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
920e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
921e9a193fcSJohn.Zolnowsky@Sun.COM/bin/diff testfile.conf.orig testfile.conf > diff.out
922e9a193fcSJohn.Zolnowsky@Sun.COMexec /bin/diff diff.out.expect diff.out
9237c478bd9Sstevel@tonic-gateEOF
9247c478bd9Sstevel@tonic-gate
9257c478bd9Sstevel@tonic-gate	set_file('runtest', <<"EOF");
9267c478bd9Sstevel@tonic-gate# test "logadmw"
9277c478bd9Sstevel@tonic-gate$envsetup
928e9a193fcSJohn.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
9297c478bd9Sstevel@tonic-gateEOF
9307c478bd9Sstevel@tonic-gate}
9317c478bd9Sstevel@tonic-gate
9327c478bd9Sstevel@tonic-gate###########################################################################
9337c478bd9Sstevel@tonic-gate#
9347c478bd9Sstevel@tonic-gate#	logadm1 -- minimal basic test of logadm rotation
9357c478bd9Sstevel@tonic-gate#
9367c478bd9Sstevel@tonic-gate###########################################################################
9377c478bd9Sstevel@tonic-gatesub logadm1 {
9387c478bd9Sstevel@tonic-gate	set_file('logfile', 'initially logfile');
9397c478bd9Sstevel@tonic-gate	set_file('logfile.0', 'initially logfile.0');
9407c478bd9Sstevel@tonic-gate	my ($stdev, $stino, $stmode, $stnlink, $stuid, $stgid, $strdev,
9417c478bd9Sstevel@tonic-gate		$stsize, $statime, $stmtime, $stctime, $stblksize, $stblocks) =
9427c478bd9Sstevel@tonic-gate		lstat 'logfile' or die "lstat logfile: $!\n";
9437c478bd9Sstevel@tonic-gate
9447c478bd9Sstevel@tonic-gate	set_file('checktest', <<"EOF");
945e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
9467c478bd9Sstevel@tonic-gate[ -s std.out ] && exit 1
9477c478bd9Sstevel@tonic-gate[ -s logfile ] && exit 1
9487c478bd9Sstevel@tonic-gate[ -f logfile.0 ] || exit 1
9497c478bd9Sstevel@tonic-gate[ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
9507c478bd9Sstevel@tonic-gate[ "`/bin/ls -i logfile.0 | /bin/awk '{ print \$1; }'`" = "$stino" ] || exit 1
9517c478bd9Sstevel@tonic-gate[ -f logfile.1 ] || exit 1
9527c478bd9Sstevel@tonic-gate[ "xinitially logfile.0" = "x`/bin/cat logfile.1`" ] || exit 1
9537c478bd9Sstevel@tonic-gateexit 0
9547c478bd9Sstevel@tonic-gateEOF
9557c478bd9Sstevel@tonic-gate
9567c478bd9Sstevel@tonic-gate	set_file('runtest', <<"EOF");
9577c478bd9Sstevel@tonic-gate# test "logadm1"
9587c478bd9Sstevel@tonic-gate$envsetup
9597c478bd9Sstevel@tonic-gateexec $bindir/logadm -f /dev/null -p now logfile >std.out 2>std.err
9607c478bd9Sstevel@tonic-gateEOF
9617c478bd9Sstevel@tonic-gate}
9627c478bd9Sstevel@tonic-gate
9637c478bd9Sstevel@tonic-gate###########################################################################
9647c478bd9Sstevel@tonic-gate#
9657c478bd9Sstevel@tonic-gate#	logadm1c -- same as logadm1 but with -c option
9667c478bd9Sstevel@tonic-gate#
9677c478bd9Sstevel@tonic-gate###########################################################################
9687c478bd9Sstevel@tonic-gatesub logadm1c {
9697c478bd9Sstevel@tonic-gate	set_file('logfile', 'initially logfile');
9707c478bd9Sstevel@tonic-gate	set_file('logfile.0', 'initially logfile.0');
9717c478bd9Sstevel@tonic-gate	my ($stdev, $stino, $stmode, $stnlink, $stuid, $stgid, $strdev,
9727c478bd9Sstevel@tonic-gate		$stsize, $statime, $stmtime, $stctime, $stblksize, $stblocks) =
9737c478bd9Sstevel@tonic-gate		lstat 'logfile' or die "lstat logfile: $!\n";
9747c478bd9Sstevel@tonic-gate
9757c478bd9Sstevel@tonic-gate	set_file('checktest', <<"EOF");
976e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
9777c478bd9Sstevel@tonic-gate[ -s std.out ] && exit 1
9787c478bd9Sstevel@tonic-gate[ -s logfile ] && exit 1
9797c478bd9Sstevel@tonic-gate[ -f logfile.0 ] || exit 1
9807c478bd9Sstevel@tonic-gate[ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
9817c478bd9Sstevel@tonic-gate[ "`/bin/ls -i logfile.0 | /bin/awk '{ print \$1; }'`" = "$stino" ] && exit 1
9827c478bd9Sstevel@tonic-gate[ -f logfile.1 ] || exit 1
9837c478bd9Sstevel@tonic-gate[ "xinitially logfile.0" = "x`/bin/cat logfile.1`" ] || exit 1
9847c478bd9Sstevel@tonic-gateexit 0
9857c478bd9Sstevel@tonic-gateEOF
9867c478bd9Sstevel@tonic-gate
9877c478bd9Sstevel@tonic-gate	set_file('runtest', <<"EOF");
9887c478bd9Sstevel@tonic-gate# test "logadm1c"
9897c478bd9Sstevel@tonic-gate$envsetup
9907c478bd9Sstevel@tonic-gateexec $bindir/logadm -f /dev/null -p now -c logfile >std.out 2>std.err
9917c478bd9Sstevel@tonic-gateEOF
9927c478bd9Sstevel@tonic-gate}
9937c478bd9Sstevel@tonic-gate
9947c478bd9Sstevel@tonic-gate###########################################################################
9957c478bd9Sstevel@tonic-gate#
9967c478bd9Sstevel@tonic-gate#	logadm2 -- minimal basic test of logadm expiration
9977c478bd9Sstevel@tonic-gate#
9987c478bd9Sstevel@tonic-gate###########################################################################
9997c478bd9Sstevel@tonic-gatesub logadm2 {
10007c478bd9Sstevel@tonic-gate	set_file('logfile', 'initially logfile');
10017c478bd9Sstevel@tonic-gate	set_file('logfile.0', 'initially logfile.0');
10027c478bd9Sstevel@tonic-gate	set_file('logfile.1', 'initially logfile.1');
10037c478bd9Sstevel@tonic-gate
10047c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
1005e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
10067c478bd9Sstevel@tonic-gate[ -s std.out ] && exit 1
10077c478bd9Sstevel@tonic-gate[ -s logfile ] && exit 1
10087c478bd9Sstevel@tonic-gate[ -f logfile.0 ] || exit 1
10097c478bd9Sstevel@tonic-gate[ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
10107c478bd9Sstevel@tonic-gate[ -f logfile.1 ] || exit 1
10117c478bd9Sstevel@tonic-gate[ "xinitially logfile.0" = "x`/bin/cat logfile.1`" ] || exit 1
10127c478bd9Sstevel@tonic-gate[ -f logfile.2 ] && exit 1
10137c478bd9Sstevel@tonic-gateexit 0
10147c478bd9Sstevel@tonic-gateEOF
10157c478bd9Sstevel@tonic-gate
10167c478bd9Sstevel@tonic-gate	set_file('runtest', <<"EOF");
10177c478bd9Sstevel@tonic-gate# test "logadm2"
10187c478bd9Sstevel@tonic-gate$envsetup
10197c478bd9Sstevel@tonic-gateexec $bindir/logadm -f /dev/null -p now logfile -C2 >std.out 2>std.err
10207c478bd9Sstevel@tonic-gateEOF
10217c478bd9Sstevel@tonic-gate}
10227c478bd9Sstevel@tonic-gate
10237c478bd9Sstevel@tonic-gate###########################################################################
10247c478bd9Sstevel@tonic-gate#
10257c478bd9Sstevel@tonic-gate#	logadm3 -- minimal basic test of logadm pre/post-commands
10267c478bd9Sstevel@tonic-gate#
10277c478bd9Sstevel@tonic-gate###########################################################################
10287c478bd9Sstevel@tonic-gatesub logadm3 {
10297c478bd9Sstevel@tonic-gate	set_file('logfile', 'initially logfile');
10307c478bd9Sstevel@tonic-gate	set_file('logfile.0', 'initially logfile.0');
10317c478bd9Sstevel@tonic-gate	set_file('logfile.1', 'initially logfile.1');
10327c478bd9Sstevel@tonic-gate
10337c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
1034e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
10357c478bd9Sstevel@tonic-gate[ -s std.out ] && exit 1
10367c478bd9Sstevel@tonic-gate[ -s logfile ] && exit 1
10377c478bd9Sstevel@tonic-gate[ -f logfile.0 ] || exit 1
10387c478bd9Sstevel@tonic-gate[ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
10397c478bd9Sstevel@tonic-gate[ -f logfile.1 ] || exit 1
10407c478bd9Sstevel@tonic-gate[ "xinitially logfile.0" = "x`/bin/cat logfile.1`" ] || exit 1
10417c478bd9Sstevel@tonic-gate[ -f logfile.2 ] && exit 1
10427c478bd9Sstevel@tonic-gate[ -f pre.out ] || exit 1
10437c478bd9Sstevel@tonic-gate[ "xpre-command-stuff" = "x`/bin/cat pre.out`" ] || exit 1
10447c478bd9Sstevel@tonic-gate[ -f post.out ] || exit 1
10457c478bd9Sstevel@tonic-gate[ "xpost-command-stuff" = "x`/bin/cat post.out`" ] || exit 1
10467c478bd9Sstevel@tonic-gateexit 0
10477c478bd9Sstevel@tonic-gateEOF
10487c478bd9Sstevel@tonic-gate
10497c478bd9Sstevel@tonic-gate	set_file('runtest', <<"EOF");
10507c478bd9Sstevel@tonic-gate# test "logadm3"
10517c478bd9Sstevel@tonic-gate$envsetup
10527c478bd9Sstevel@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
10537c478bd9Sstevel@tonic-gateEOF
10547c478bd9Sstevel@tonic-gate}
10557c478bd9Sstevel@tonic-gate
10567c478bd9Sstevel@tonic-gate###########################################################################
10577c478bd9Sstevel@tonic-gate#
10587c478bd9Sstevel@tonic-gate#	logadm4 -- test of -t template
10597c478bd9Sstevel@tonic-gate#
10607c478bd9Sstevel@tonic-gate###########################################################################
10617c478bd9Sstevel@tonic-gatesub logadm4 {
10627c478bd9Sstevel@tonic-gate	set_file('logfile', 'initially logfile');
10637c478bd9Sstevel@tonic-gate
10647c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
1065e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
10667c478bd9Sstevel@tonic-gate[ -s std.out ] && exit 1
10677c478bd9Sstevel@tonic-gate[ -s logfile ] && exit 1
10687c478bd9Sstevel@tonic-gateTZ=UTC export TZ
10697c478bd9Sstevel@tonic-gated=`/bin/date +%d`
10707c478bd9Sstevel@tonic-gate[ -f logfile.$d ] || exit 1
10717c478bd9Sstevel@tonic-gate[ "xinitially logfile" = "x`/bin/cat logfile.$d`" ] || exit 1
10727c478bd9Sstevel@tonic-gateexit 0
10737c478bd9Sstevel@tonic-gateEOF
10747c478bd9Sstevel@tonic-gate
10757c478bd9Sstevel@tonic-gate	set_file('runtest', <<"EOF");
10767c478bd9Sstevel@tonic-gate# test "logadm4"
10777c478bd9Sstevel@tonic-gate$envsetup
10787c478bd9Sstevel@tonic-gateexec $bindir/logadm -f /dev/null -p now logfile -t '\$file.\%d' >std.out 2>std.err
10797c478bd9Sstevel@tonic-gateEOF
10807c478bd9Sstevel@tonic-gate}
10817c478bd9Sstevel@tonic-gate
10827c478bd9Sstevel@tonic-gate###########################################################################
10837c478bd9Sstevel@tonic-gate#
10847c478bd9Sstevel@tonic-gate#	logadm5 -- test of -R cmd and -E cmd
10857c478bd9Sstevel@tonic-gate#
10867c478bd9Sstevel@tonic-gate###########################################################################
10877c478bd9Sstevel@tonic-gatesub logadm5 {
10887c478bd9Sstevel@tonic-gate	set_file('logfile', 'initially logfile');
10897c478bd9Sstevel@tonic-gate	set_file('logfile.0', 'initially logfile.0');
10907c478bd9Sstevel@tonic-gate
10917c478bd9Sstevel@tonic-gate	set_file('cmd.out.expect', <<'EOF');
10927c478bd9Sstevel@tonic-gatejust rotated: initially logfile
10937c478bd9Sstevel@tonic-gatejust expired: initially logfile.0
10947c478bd9Sstevel@tonic-gateEOF
10957c478bd9Sstevel@tonic-gate
10967c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
1097e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
10987c478bd9Sstevel@tonic-gate[ -s std.out ] && exit 1
10997c478bd9Sstevel@tonic-gate[ -s logfile ] && exit 1
11007c478bd9Sstevel@tonic-gate[ -f logfile.0 ] || exit 1
11017c478bd9Sstevel@tonic-gate[ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
11027c478bd9Sstevel@tonic-gate[ -f logfile.1 ] || exit 1
11037c478bd9Sstevel@tonic-gate[ "xinitially logfile.0" = "x`/bin/cat logfile.1`" ] || exit 1
1104e9a193fcSJohn.Zolnowsky@Sun.COMexec /bin/diff cmd.out.expect cmd.out
11057c478bd9Sstevel@tonic-gateEOF
11067c478bd9Sstevel@tonic-gate
11077c478bd9Sstevel@tonic-gate	set_file('runtest', <<"EOF");
11087c478bd9Sstevel@tonic-gate# test "logadm5"
11097c478bd9Sstevel@tonic-gate$envsetup
11107c478bd9Sstevel@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
11117c478bd9Sstevel@tonic-gateEOF
11127c478bd9Sstevel@tonic-gate}
11137c478bd9Sstevel@tonic-gate
11147c478bd9Sstevel@tonic-gate###########################################################################
11157c478bd9Sstevel@tonic-gate#
11167c478bd9Sstevel@tonic-gate#	logadm6 -- test of -m, -o, -g
11177c478bd9Sstevel@tonic-gate#
11187c478bd9Sstevel@tonic-gate###########################################################################
11197c478bd9Sstevel@tonic-gatesub logadm6 {
11207c478bd9Sstevel@tonic-gate        set_file('logfile', 'initially logfile');
11217c478bd9Sstevel@tonic-gate
11227c478bd9Sstevel@tonic-gate        set_file('std.err.expect', <<'EOF');
11237c478bd9Sstevel@tonic-gatelogadm: Warning: command failed: /bin/chown _nonexistentuser_:_nonexistentgroup_ logfile
11247c478bd9Sstevel@tonic-gatechown: unknown group id _nonexistentgroup_
11257c478bd9Sstevel@tonic-gateEOF
11267c478bd9Sstevel@tonic-gate
11277c478bd9Sstevel@tonic-gate        set_file('checktest', <<'EOF');
1128e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] || exit 1;
11297c478bd9Sstevel@tonic-gate[ -s std.out ] && exit 1
11307c478bd9Sstevel@tonic-gate[ -s logfile ] && exit 1
11317c478bd9Sstevel@tonic-gate[ -f logfile.0 ] || exit 1
11327c478bd9Sstevel@tonic-gate[ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
11337c478bd9Sstevel@tonic-gate[ "`/bin/ls -l logfile | /bin/awk '{ print $1; }'`" = "-r----x--x" ] || exit 1
1134e9a193fcSJohn.Zolnowsky@Sun.COMexec /bin/diff std.err.expect std.err
11357c478bd9Sstevel@tonic-gateEOF
11367c478bd9Sstevel@tonic-gate
11377c478bd9Sstevel@tonic-gate        set_file('runtest', <<"EOF");
11387c478bd9Sstevel@tonic-gate# test "logadm6"
11397c478bd9Sstevel@tonic-gate$envsetup
11407c478bd9Sstevel@tonic-gateexec $bindir/logadm -f /dev/null -p now logfile -m 411 -o _nonexistentuser_ -g _nonexistentgroup_ >std.out 2>std.err
11417c478bd9Sstevel@tonic-gateEOF
11427c478bd9Sstevel@tonic-gate}
11437c478bd9Sstevel@tonic-gate
11447c478bd9Sstevel@tonic-gate###########################################################################
11457c478bd9Sstevel@tonic-gate#
11467c478bd9Sstevel@tonic-gate#       logadm7 -- test running through a conffile
11477c478bd9Sstevel@tonic-gate#
11487c478bd9Sstevel@tonic-gate###########################################################################
11497c478bd9Sstevel@tonic-gatesub logadm7 {
11507c478bd9Sstevel@tonic-gate	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
11517c478bd9Sstevel@tonic-gate	set_file('dir1/syslog', 'initially dir1/syslog');
11527c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.0', 'initially dir1/syslog.0');
11537c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.1', 'initially dir1/syslog.1');
11547c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.2', 'initially dir1/syslog.2');
11557c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.3', 'initially dir1/syslog.3');
11567c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.4', 'initially dir1/syslog.4');
11577c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.5', 'initially dir1/syslog.5');
11587c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.6', 'initially dir1/syslog.6');
11597c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.7', 'initially dir1/syslog.7');
11607c478bd9Sstevel@tonic-gate	mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
11617c478bd9Sstevel@tonic-gate	set_file('dir2/messages', 'initially dir2/messages');
11627c478bd9Sstevel@tonic-gate	set_file('dir2/messages.0', 'initially dir2/messages.0');
11637c478bd9Sstevel@tonic-gate	set_file('dir2/messages.1', 'initially dir2/messages.1');
11647c478bd9Sstevel@tonic-gate	set_file('dir2/messages.2', 'initially dir2/messages.2');
11657c478bd9Sstevel@tonic-gate	set_file('dir2/messages.3', 'initially dir2/messages.3');
11667c478bd9Sstevel@tonic-gate
11677c478bd9Sstevel@tonic-gate	set_file('logadm.conf', <<'EOF');
11687c478bd9Sstevel@tonic-gate#
11697c478bd9Sstevel@tonic-gate# logadm.conf
11707c478bd9Sstevel@tonic-gate#
11717c478bd9Sstevel@tonic-gate#	this comment # has at least another #-sign in it #...
11727c478bd9Sstevel@tonic-gate#
11737c478bd9Sstevel@tonic-gate# Default settings for system log file management.
1174*bbf21555SRichard Lowe# The -w option to logadm(8) is the preferred way to write to this file,
11757c478bd9Sstevel@tonic-gate# but if you do edit it by hand, use "logadm -V" to check it for errors.
11767c478bd9Sstevel@tonic-gate# but if you do edit it by hand, use "logadm -V" to check it for errors.
11777c478bd9Sstevel@tonic-gate#
11787c478bd9Sstevel@tonic-gate# The format of lines in this file is:
11797c478bd9Sstevel@tonic-gate#       <logname> <options>
11807c478bd9Sstevel@tonic-gate# For each logname listed here, the default options to logadm
11817c478bd9Sstevel@tonic-gate# are given.  Options given on the logadm command line override
11827c478bd9Sstevel@tonic-gate# the defaults contained in this file.
11837c478bd9Sstevel@tonic-gate#
11847c478bd9Sstevel@tonic-gate# logadm typically runs early every morning via an entry in
11857c478bd9Sstevel@tonic-gate# root's crontab (see crontab(1)).
11867c478bd9Sstevel@tonic-gate#
1187fdaa2824SBryan Cantrilldir1/syslog -C 8 -a 'echo kill -HUP `cat /var/run/*syslog*pid` >> cmd.out'
1188fdaa2824SBryan Cantrilldir2/messages -C 4 -a 'echo kill -HUP `cat /var/run/*syslog*pid` >> cmd.out'
11897c478bd9Sstevel@tonic-gate#
1190*bbf21555SRichard Lowe# The entry below is used by turnacct(8)
11917c478bd9Sstevel@tonic-gate#
11927c478bd9Sstevel@tonic-gate/var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
11937c478bd9Sstevel@tonic-gateEOF
11947c478bd9Sstevel@tonic-gate
11957c478bd9Sstevel@tonic-gate	system("/bin/cp logadm.conf logadm.conf.orig");
11967c478bd9Sstevel@tonic-gate
1197fdaa2824SBryan Cantrill	$pid=`cat /var/run/*syslog*pid`;
11987c478bd9Sstevel@tonic-gate	chomp $pid;
11997c478bd9Sstevel@tonic-gate	set_file('cmd.out.expect', <<"EOF");
12007c478bd9Sstevel@tonic-gatekill -HUP $pid
12017c478bd9Sstevel@tonic-gatesecond kill -HUP $pid
1202e9a193fcSJohn.Zolnowsky@Sun.COMEOF
1203e9a193fcSJohn.Zolnowsky@Sun.COM
1204e9a193fcSJohn.Zolnowsky@Sun.COM	set_file('sed.out.expect', <<'EOF');
1205*bbf21555SRichard Lowe# This file holds internal data for logadm(8).
1206e9a193fcSJohn.Zolnowsky@Sun.COM# Do not edit.
1207e9a193fcSJohn.Zolnowsky@Sun.COMdir1/syslog
1208e9a193fcSJohn.Zolnowsky@Sun.COMdir2/messages
12097c478bd9Sstevel@tonic-gateEOF
12107c478bd9Sstevel@tonic-gate
12117c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
1212e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
12137c478bd9Sstevel@tonic-gate[ -s std.out ] && exit 1
1214e9a193fcSJohn.Zolnowsky@Sun.COM[ -s logadm.timestamps ] || exit 1
12157c478bd9Sstevel@tonic-gate[ -s std.err2 ] && exit 1
12167c478bd9Sstevel@tonic-gate[ -s std.out2 ] && exit 1
12177c478bd9Sstevel@tonic-gate[ -s std.err3 ] && exit 1
12187c478bd9Sstevel@tonic-gate[ -s std.out3 ] && exit 1
12197c478bd9Sstevel@tonic-gate[ -s std.err4 ] && exit 1
12207c478bd9Sstevel@tonic-gate[ -s std.out4 ] && exit 1
12217c478bd9Sstevel@tonic-gate[ -f dir1/syslog ] || exit 1
12227c478bd9Sstevel@tonic-gate[ "xsomething" = "x`/bin/cat dir1/syslog`" ] || exit 1
12237c478bd9Sstevel@tonic-gate[ -f dir1/syslog.0 ] || exit 1
12247c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
12257c478bd9Sstevel@tonic-gate[ -f dir1/syslog.1 ] || exit 1
12267c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
12277c478bd9Sstevel@tonic-gate[ -f dir1/syslog.2 ] || exit 1
12287c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
12297c478bd9Sstevel@tonic-gate[ -f dir1/syslog.3 ] || exit 1
12307c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
12317c478bd9Sstevel@tonic-gate[ -f dir1/syslog.4 ] || exit 1
12327c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
12337c478bd9Sstevel@tonic-gate[ -f dir1/syslog.5 ] || exit 1
12347c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
12357c478bd9Sstevel@tonic-gate[ -f dir1/syslog.6 ] || exit 1
12367c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
12377c478bd9Sstevel@tonic-gate[ -f dir1/syslog.7 ] || exit 1
12387c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
12397c478bd9Sstevel@tonic-gate[ -f dir1/syslog.8 ] && exit 1
12407c478bd9Sstevel@tonic-gate
12417c478bd9Sstevel@tonic-gate[ -s dir2/messages ] && exit 1
12427c478bd9Sstevel@tonic-gate[ -f dir2/messages.0 ] || exit 1
12437c478bd9Sstevel@tonic-gate[ "xsomething" = "x`/bin/cat dir2/messages.0`" ] || exit 1
12447c478bd9Sstevel@tonic-gate[ -f dir2/messages.1 ] || exit 1
12457c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages" = "x`/bin/cat dir2/messages.1`" ] || exit 1
12467c478bd9Sstevel@tonic-gate[ -f dir2/messages.2 ] || exit 1
12477c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.2`" ] || exit 1
12487c478bd9Sstevel@tonic-gate[ -f dir2/messages.3 ] || exit 1
12497c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.3`" ] || exit 1
12507c478bd9Sstevel@tonic-gate[ -f dir2/messages.4 ] && exit 1
1251e9a193fcSJohn.Zolnowsky@Sun.COM/bin/sed "s/ -P '[^']*' *//" < logadm.timestamps > sed.out
1252e9a193fcSJohn.Zolnowsky@Sun.COM/bin/diff sed.out.expect sed.out || exit 1
1253e9a193fcSJohn.Zolnowsky@Sun.COMexec /bin/diff logadm.conf.orig logadm.conf
12547c478bd9Sstevel@tonic-gateEOF
12557c478bd9Sstevel@tonic-gate
12567c478bd9Sstevel@tonic-gate        # first logadm call will rotate both syslog and messages
12577c478bd9Sstevel@tonic-gate        # second one won't because size is zero
12587c478bd9Sstevel@tonic-gate        # third one won't because of -P timestamps stored in conffile
12597c478bd9Sstevel@tonic-gate        # fourth one will do messages because of -p now on command line
12607c478bd9Sstevel@tonic-gate        set_file('runtest', <<"EOF");
12617c478bd9Sstevel@tonic-gate# test "logadm7"
12627c478bd9Sstevel@tonic-gate$envsetup
1263e9a193fcSJohn.Zolnowsky@Sun.COM$bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err || exit 1
1264e9a193fcSJohn.Zolnowsky@Sun.COM$bindir/logadm -f logadm.conf -F logadm.timestamps dir1/syslog dir2/messages >std.out2 2>std.err2 || exit 1
12657c478bd9Sstevel@tonic-gateecho something > dir1/syslog
12667c478bd9Sstevel@tonic-gateecho something > dir2/messages
1267e9a193fcSJohn.Zolnowsky@Sun.COM$bindir/logadm -f logadm.conf -F logadm.timestamps >std.out3 2>std.err3 || exit 1
1268fdaa2824SBryan Cantrillexec $bindir/logadm -f logadm.conf -F logadm.timestamps dir2/messages -p now -a 'echo second kill -HUP `cat /var/run/*syslog*pid` >> cmd.out' >std.out4 2>std.err4
12697c478bd9Sstevel@tonic-gateEOF
12707c478bd9Sstevel@tonic-gate}
12717c478bd9Sstevel@tonic-gate
12727c478bd9Sstevel@tonic-gate###########################################################################
12737c478bd9Sstevel@tonic-gate#
12747c478bd9Sstevel@tonic-gate#       logadm8 -- test of -z
12757c478bd9Sstevel@tonic-gate#
12767c478bd9Sstevel@tonic-gate###########################################################################
12777c478bd9Sstevel@tonic-gatesub logadm8 {
12787c478bd9Sstevel@tonic-gate	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
12797c478bd9Sstevel@tonic-gate	set_file('dir1/syslog', 'initially dir1/syslog');
12807c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.0', 'initially dir1/syslog.0');
12817c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.1', 'initially dir1/syslog.1');
12827c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.2', 'initially dir1/syslog.2');
12837c478bd9Sstevel@tonic-gate	system("/bin/gzip dir1/syslog.2");
12847c478bd9Sstevel@tonic-gate	die "gzip dir1/syslog.2 didn't work\n" unless -f 'dir1/syslog.2.gz';
12857c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.3', 'initially dir1/syslog.3');
12867c478bd9Sstevel@tonic-gate	system("/bin/gzip dir1/syslog.3");
12877c478bd9Sstevel@tonic-gate	die "gzip dir1/syslog.3 didn't work\n" unless -f 'dir1/syslog.3.gz';
12887c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.4', 'initially dir1/syslog.4');
12897c478bd9Sstevel@tonic-gate	system("/bin/gzip dir1/syslog.4");
12907c478bd9Sstevel@tonic-gate	die "gzip dir1/syslog.4 didn't work\n" unless -f 'dir1/syslog.4.gz';
12917c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.5', 'initially dir1/syslog.5');
12927c478bd9Sstevel@tonic-gate	system("/bin/gzip dir1/syslog.5");
12937c478bd9Sstevel@tonic-gate	die "gzip dir1/syslog.5 didn't work\n" unless -f 'dir1/syslog.5.gz';
12947c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.6', 'initially dir1/syslog.6');
12957c478bd9Sstevel@tonic-gate	system("/bin/gzip dir1/syslog.6");
12967c478bd9Sstevel@tonic-gate	die "gzip dir1/syslog.6 didn't work\n" unless -f 'dir1/syslog.6.gz';
12977c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.7', 'initially dir1/syslog.7');
12987c478bd9Sstevel@tonic-gate	system("/bin/gzip dir1/syslog.7");
12997c478bd9Sstevel@tonic-gate	die "gzip dir1/syslog.7 didn't work\n" unless -f 'dir1/syslog.7.gz';
13007c478bd9Sstevel@tonic-gate
13017c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
1302e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
13037c478bd9Sstevel@tonic-gate[ -s std.out ] && exit 1
13047c478bd9Sstevel@tonic-gate[ -f dir1/syslog ] || exit 1
13057c478bd9Sstevel@tonic-gate[ -s dir1/syslog ] && exit 1
13067c478bd9Sstevel@tonic-gate[ -f dir1/syslog.0 ] || exit 1
13077c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
13087c478bd9Sstevel@tonic-gate[ -f dir1/syslog.1 ] || exit 1
13097c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
13107c478bd9Sstevel@tonic-gate[ -f dir1/syslog.2.gz ] || exit 1
13117c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.1" = "x`/bin/gzcat dir1/syslog.2.gz`" ] || exit 1
13127c478bd9Sstevel@tonic-gate[ -f dir1/syslog.3.gz ] || exit 1
13137c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.2" = "x`/bin/gzcat dir1/syslog.3.gz`" ] || exit 1
13147c478bd9Sstevel@tonic-gate[ -f dir1/syslog.4.gz ] || exit 1
13157c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.3" = "x`/bin/gzcat dir1/syslog.4.gz`" ] || exit 1
13167c478bd9Sstevel@tonic-gate[ -f dir1/syslog.5.gz ] || exit 1
13177c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.4" = "x`/bin/gzcat dir1/syslog.5.gz`" ] || exit 1
13187c478bd9Sstevel@tonic-gate[ -f dir1/syslog.6.gz ] || exit 1
13197c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.5" = "x`/bin/gzcat dir1/syslog.6.gz`" ] || exit 1
13207c478bd9Sstevel@tonic-gate[ -f dir1/syslog.7.gz ] || exit 1
13217c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.6" = "x`/bin/gzcat dir1/syslog.7.gz`" ] || exit 1
13227c478bd9Sstevel@tonic-gate[ -f dir1/syslog.8 ] && exit 1
13237c478bd9Sstevel@tonic-gate[ -f dir1/syslog.8.gz ] && exit 1
13247c478bd9Sstevel@tonic-gateexit 0
13257c478bd9Sstevel@tonic-gateEOF
13267c478bd9Sstevel@tonic-gate
13277c478bd9Sstevel@tonic-gate        set_file('runtest', <<"EOF");
13287c478bd9Sstevel@tonic-gate# test "logadm8"
13297c478bd9Sstevel@tonic-gate$envsetup
13307c478bd9Sstevel@tonic-gateexec $bindir/logadm -f /dev/null dir1/syslog -z 2 -C 8 >std.out 2>std.err
13317c478bd9Sstevel@tonic-gateEOF
13327c478bd9Sstevel@tonic-gate}
13337c478bd9Sstevel@tonic-gate
13347c478bd9Sstevel@tonic-gate###########################################################################
13357c478bd9Sstevel@tonic-gate#
13367c478bd9Sstevel@tonic-gate#       logadm9 -- test of age check
13377c478bd9Sstevel@tonic-gate#
13387c478bd9Sstevel@tonic-gate###########################################################################
13397c478bd9Sstevel@tonic-gatesub logadm9 {
13407c478bd9Sstevel@tonic-gate	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
13417c478bd9Sstevel@tonic-gate	set_file('dir1/syslog', 'initially dir1/syslog');
13427c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.0', 'initially dir1/syslog.0');
13437c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.1', 'initially dir1/syslog.1');
13447c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.2', 'initially dir1/syslog.2');
13457c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.3', 'initially dir1/syslog.3');
13467c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.4', 'initially dir1/syslog.4');
13477c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.5', 'initially dir1/syslog.5');
13487c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.6', 'initially dir1/syslog.6');
13497c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.7', 'initially dir1/syslog.7');
1350e9a193fcSJohn.Zolnowsky@Sun.COM	set_file('dir1/notes', 'initially dir1/notes');
13517c478bd9Sstevel@tonic-gate	mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
13527c478bd9Sstevel@tonic-gate	set_file('dir2/messages', 'initially dir2/messages');
13537c478bd9Sstevel@tonic-gate	set_file('dir2/messages.0', 'initially dir2/messages.0');
13547c478bd9Sstevel@tonic-gate	set_file('dir2/messages.1', 'initially dir2/messages.1');
13557c478bd9Sstevel@tonic-gate	set_file('dir2/messages.2', 'initially dir2/messages.2');
13567c478bd9Sstevel@tonic-gate	set_file('dir2/messages.3', 'initially dir2/messages.3');
1357e9a193fcSJohn.Zolnowsky@Sun.COM	set_file('dir2/log', 'initially dir2/log');
13587c478bd9Sstevel@tonic-gate
13597c478bd9Sstevel@tonic-gate	$now = time;
13607c478bd9Sstevel@tonic-gate	$nowstr = gmtime($now);
13617c478bd9Sstevel@tonic-gate	# a week minus 30 seconds ago...
13627c478bd9Sstevel@tonic-gate	# technically not a full week, but the heuristic used by logadm
13637c478bd9Sstevel@tonic-gate	# should think this is "close enough" to a full week
13647c478bd9Sstevel@tonic-gate	$closetoweeksecs = $now - (60 * 60 * 24 * 7 - 30);
13657c478bd9Sstevel@tonic-gate	$closetoweek = gmtime($closetoweeksecs);
13667c478bd9Sstevel@tonic-gate	# a week minus six hours ago...
13677c478bd9Sstevel@tonic-gate	$lessthanweeksecs = $now - (60 * 60 * 24 * 7 - 60 * 60 * 6);
13687c478bd9Sstevel@tonic-gate	$lessthanweek = gmtime($lessthanweeksecs);
13697c478bd9Sstevel@tonic-gate
13707c478bd9Sstevel@tonic-gate	set_file('logadm.conf', <<"EOF");
13717c478bd9Sstevel@tonic-gate# now: $nowstr is $now
13727c478bd9Sstevel@tonic-gate# $closetoweek is $closetoweeksecs
13737c478bd9Sstevel@tonic-gatedir1/syslog -C 8 -P '$closetoweek'
1374e9a193fcSJohn.Zolnowsky@Sun.COMdir2/log -C 4
13757c478bd9Sstevel@tonic-gate# $lessthanweek is $lessthanweeksecs
1376e9a193fcSJohn.Zolnowsky@Sun.COMdir1/notes -C 2 -P '$lessthanweek'
1377e9a193fcSJohn.Zolnowsky@Sun.COMdir2/messages -C 4
1378e9a193fcSJohn.Zolnowsky@Sun.COMEOF
1379e9a193fcSJohn.Zolnowsky@Sun.COM	set_file('logadm.timestamps', <<"EOF");
1380e9a193fcSJohn.Zolnowsky@Sun.COMdir2/log -P '$closetoweek'
1381e9a193fcSJohn.Zolnowsky@Sun.COMdir2/messages -P '$lessthanweek'
1382e9a193fcSJohn.Zolnowsky@Sun.COMEOF
1383e9a193fcSJohn.Zolnowsky@Sun.COM
1384e9a193fcSJohn.Zolnowsky@Sun.COM	set_file('sed.out.expect', <<"EOF");
1385*bbf21555SRichard Lowe# This file holds internal data for logadm(8).
1386e9a193fcSJohn.Zolnowsky@Sun.COM# Do not edit.
1387e9a193fcSJohn.Zolnowsky@Sun.COMdir1/syslog
1388e9a193fcSJohn.Zolnowsky@Sun.COMdir2/log
1389e9a193fcSJohn.Zolnowsky@Sun.COMdir1/notes
1390e9a193fcSJohn.Zolnowsky@Sun.COMdir2/messages
13917c478bd9Sstevel@tonic-gateEOF
13927c478bd9Sstevel@tonic-gate
13937c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
1394e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
13957c478bd9Sstevel@tonic-gate[ -s std.out ] && exit 1
13967c478bd9Sstevel@tonic-gate[ -f dir1/syslog ] || exit 1
13977c478bd9Sstevel@tonic-gate[ -s dir1/syslog ] && exit 1
13987c478bd9Sstevel@tonic-gate[ -f dir1/syslog.0 ] || exit 1
13997c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
14007c478bd9Sstevel@tonic-gate[ -f dir1/syslog.1 ] || exit 1
14017c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
14027c478bd9Sstevel@tonic-gate[ -f dir1/syslog.2 ] || exit 1
14037c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
14047c478bd9Sstevel@tonic-gate[ -f dir1/syslog.3 ] || exit 1
14057c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
14067c478bd9Sstevel@tonic-gate[ -f dir1/syslog.4 ] || exit 1
14077c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
14087c478bd9Sstevel@tonic-gate[ -f dir1/syslog.5 ] || exit 1
14097c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
14107c478bd9Sstevel@tonic-gate[ -f dir1/syslog.6 ] || exit 1
14117c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
14127c478bd9Sstevel@tonic-gate[ -f dir1/syslog.7 ] || exit 1
14137c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
14147c478bd9Sstevel@tonic-gate[ -f dir1/syslog.8 ] && exit 1
14157c478bd9Sstevel@tonic-gate
1416e9a193fcSJohn.Zolnowsky@Sun.COM[ -s dir1/notes ] || exit 1
1417e9a193fcSJohn.Zolnowsky@Sun.COM[ "xinitially dir1/notes" = "x`/bin/cat dir1/notes`" ] || exit 1
1418e9a193fcSJohn.Zolnowsky@Sun.COM[ -f dir1/notes.0 ] && exit 1
1419e9a193fcSJohn.Zolnowsky@Sun.COM
14207c478bd9Sstevel@tonic-gate[ -f dir2/messages ] || exit 1
14217c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages" = "x`/bin/cat dir2/messages`" ] || exit 1
14227c478bd9Sstevel@tonic-gate[ -f dir2/messages.0 ] || exit 1
14237c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.0`" ] || exit 1
14247c478bd9Sstevel@tonic-gate[ -f dir2/messages.1 ] || exit 1
14257c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.1`" ] || exit 1
14267c478bd9Sstevel@tonic-gate[ -f dir2/messages.2 ] || exit 1
14277c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages.2" = "x`/bin/cat dir2/messages.2`" ] || exit 1
14287c478bd9Sstevel@tonic-gate[ -f dir2/messages.3 ] || exit 1
14297c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages.3" = "x`/bin/cat dir2/messages.3`" ] || exit 1
14307c478bd9Sstevel@tonic-gate[ -f dir2/messages.4 ] && exit 1
1431e9a193fcSJohn.Zolnowsky@Sun.COM
1432e9a193fcSJohn.Zolnowsky@Sun.COM[ -f dir2/log ] || exit 1
1433e9a193fcSJohn.Zolnowsky@Sun.COM[ -s dir2/log ] && exit 1
1434e9a193fcSJohn.Zolnowsky@Sun.COM[ -f dir2/log.0 ] || exit 1
1435e9a193fcSJohn.Zolnowsky@Sun.COM[ "xinitially dir2/log" = "x`/bin/cat dir2/log.0`" ] || exit 1
1436e9a193fcSJohn.Zolnowsky@Sun.COM[ -f dir2/log.1 ] && exit 1
1437e9a193fcSJohn.Zolnowsky@Sun.COM
1438e9a193fcSJohn.Zolnowsky@Sun.COM/bin/sed "s/ -P '[^']*' *//" < logadm.timestamps > sed.out
1439e9a193fcSJohn.Zolnowsky@Sun.COM/bin/diff sed.out.expect sed.out || exit 1
1440e9a193fcSJohn.Zolnowsky@Sun.COM/bin/sed -n "s/ -P '[^']*' */<&>/p" < logadm.conf > sed.out
1441e9a193fcSJohn.Zolnowsky@Sun.COM[ -s sed.out ] && exit 1
14427c478bd9Sstevel@tonic-gateexit 0
14437c478bd9Sstevel@tonic-gateEOF
14447c478bd9Sstevel@tonic-gate
14457c478bd9Sstevel@tonic-gate        set_file('runtest', <<"EOF");
14467c478bd9Sstevel@tonic-gate# test "logadm9"
14477c478bd9Sstevel@tonic-gate$envsetup
1448e9a193fcSJohn.Zolnowsky@Sun.COMexec $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err
14497c478bd9Sstevel@tonic-gateEOF
14507c478bd9Sstevel@tonic-gate}
14517c478bd9Sstevel@tonic-gate
14527c478bd9Sstevel@tonic-gate###########################################################################
14537c478bd9Sstevel@tonic-gate#
14547c478bd9Sstevel@tonic-gate#       logadm9d -- test of age check like logadm9, but age is a couple days
14557c478bd9Sstevel@tonic-gate#
14567c478bd9Sstevel@tonic-gate###########################################################################
14577c478bd9Sstevel@tonic-gatesub logadm9d {
14587c478bd9Sstevel@tonic-gate	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
14597c478bd9Sstevel@tonic-gate	set_file('dir1/syslog', 'initially dir1/syslog');
14607c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.0', 'initially dir1/syslog.0');
14617c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.1', 'initially dir1/syslog.1');
14627c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.2', 'initially dir1/syslog.2');
14637c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.3', 'initially dir1/syslog.3');
14647c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.4', 'initially dir1/syslog.4');
14657c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.5', 'initially dir1/syslog.5');
14667c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.6', 'initially dir1/syslog.6');
14677c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.7', 'initially dir1/syslog.7');
14687c478bd9Sstevel@tonic-gate	mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
14697c478bd9Sstevel@tonic-gate	set_file('dir2/messages', 'initially dir2/messages');
14707c478bd9Sstevel@tonic-gate	set_file('dir2/messages.0', 'initially dir2/messages.0');
14717c478bd9Sstevel@tonic-gate	set_file('dir2/messages.1', 'initially dir2/messages.1');
14727c478bd9Sstevel@tonic-gate	set_file('dir2/messages.2', 'initially dir2/messages.2');
14737c478bd9Sstevel@tonic-gate	set_file('dir2/messages.3', 'initially dir2/messages.3');
14747c478bd9Sstevel@tonic-gate
14757c478bd9Sstevel@tonic-gate	$now = time;
14767c478bd9Sstevel@tonic-gate	$nowstr = gmtime($now);
14777c478bd9Sstevel@tonic-gate	# a day minus 30 seconds ago...
14787c478bd9Sstevel@tonic-gate	$closetodaysecs = $now - (60 * 60 * 24 - 30);
14797c478bd9Sstevel@tonic-gate	$closetoday = gmtime($closetodaysecs);
14807c478bd9Sstevel@tonic-gate	# a day minus six hours ago...
14817c478bd9Sstevel@tonic-gate	$lessthandaysecs = $now - (60 * 60 * 24 - 60 * 60 * 6);
14827c478bd9Sstevel@tonic-gate	$lessthanday = gmtime($lessthandaysecs);
14837c478bd9Sstevel@tonic-gate
14847c478bd9Sstevel@tonic-gate	set_file('logadm.conf', <<"EOF");
14857c478bd9Sstevel@tonic-gate# now: $nowstr is $now
14867c478bd9Sstevel@tonic-gate# $closetoday is $closetodaysecs
14877c478bd9Sstevel@tonic-gatedir1/syslog -p 1d -C 8 -P '$closetoday'
14887c478bd9Sstevel@tonic-gate# $lessthanday is $lessthandaysecs
14897c478bd9Sstevel@tonic-gatedir2/messages -p 1d -C 4 -P '$lessthanday'
14907c478bd9Sstevel@tonic-gateEOF
14917c478bd9Sstevel@tonic-gate
14927c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
1493e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
14947c478bd9Sstevel@tonic-gate[ -s std.out ] && exit 1
14957c478bd9Sstevel@tonic-gate[ -f dir1/syslog ] || exit 1
14967c478bd9Sstevel@tonic-gate[ -s dir1/syslog ] && exit 1
14977c478bd9Sstevel@tonic-gate[ -f dir1/syslog.0 ] || exit 1
14987c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
14997c478bd9Sstevel@tonic-gate[ -f dir1/syslog.1 ] || exit 1
15007c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
15017c478bd9Sstevel@tonic-gate[ -f dir1/syslog.2 ] || exit 1
15027c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
15037c478bd9Sstevel@tonic-gate[ -f dir1/syslog.3 ] || exit 1
15047c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
15057c478bd9Sstevel@tonic-gate[ -f dir1/syslog.4 ] || exit 1
15067c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
15077c478bd9Sstevel@tonic-gate[ -f dir1/syslog.5 ] || exit 1
15087c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
15097c478bd9Sstevel@tonic-gate[ -f dir1/syslog.6 ] || exit 1
15107c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
15117c478bd9Sstevel@tonic-gate[ -f dir1/syslog.7 ] || exit 1
15127c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
15137c478bd9Sstevel@tonic-gate[ -f dir1/syslog.8 ] && exit 1
15147c478bd9Sstevel@tonic-gate
15157c478bd9Sstevel@tonic-gate[ -f dir2/messages ] || exit 1
15167c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages" = "x`/bin/cat dir2/messages`" ] || exit 1
15177c478bd9Sstevel@tonic-gate[ -f dir2/messages.0 ] || exit 1
15187c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.0`" ] || exit 1
15197c478bd9Sstevel@tonic-gate[ -f dir2/messages.1 ] || exit 1
15207c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.1`" ] || exit 1
15217c478bd9Sstevel@tonic-gate[ -f dir2/messages.2 ] || exit 1
15227c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages.2" = "x`/bin/cat dir2/messages.2`" ] || exit 1
15237c478bd9Sstevel@tonic-gate[ -f dir2/messages.3 ] || exit 1
15247c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages.3" = "x`/bin/cat dir2/messages.3`" ] || exit 1
15257c478bd9Sstevel@tonic-gate[ -f dir2/messages.4 ] && exit 1
15267c478bd9Sstevel@tonic-gateexit 0
15277c478bd9Sstevel@tonic-gateEOF
15287c478bd9Sstevel@tonic-gate
15297c478bd9Sstevel@tonic-gate        set_file('runtest', <<"EOF");
15307c478bd9Sstevel@tonic-gate# test "logadm9d"
15317c478bd9Sstevel@tonic-gate$envsetup
1532e9a193fcSJohn.Zolnowsky@Sun.COMexec $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err
15337c478bd9Sstevel@tonic-gateEOF
15347c478bd9Sstevel@tonic-gate}
15357c478bd9Sstevel@tonic-gate
15367c478bd9Sstevel@tonic-gate###########################################################################
15377c478bd9Sstevel@tonic-gate#
15387c478bd9Sstevel@tonic-gate#       logadm10 -- test of size-based rotation check
15397c478bd9Sstevel@tonic-gate#
15407c478bd9Sstevel@tonic-gate###########################################################################
15417c478bd9Sstevel@tonic-gatesub logadm10 {
15427c478bd9Sstevel@tonic-gate	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
15437c478bd9Sstevel@tonic-gate	set_file('dir1/syslog', 'initially dir1/syslogXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
15447c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.0', 'initially dir1/syslog.0');
15457c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.1', 'initially dir1/syslog.1');
15467c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.2', 'initially dir1/syslog.2');
15477c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.3', 'initially dir1/syslog.3');
15487c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.4', 'initially dir1/syslog.4');
15497c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.5', 'initially dir1/syslog.5');
15507c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.6', 'initially dir1/syslog.6');
15517c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.7', 'initially dir1/syslog.7');
15527c478bd9Sstevel@tonic-gate	mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
15537c478bd9Sstevel@tonic-gate	set_file('dir2/messages', 'initially dir2/messages');
15547c478bd9Sstevel@tonic-gate	set_file('dir2/messages.0', 'initially dir2/messages.0');
15557c478bd9Sstevel@tonic-gate	set_file('dir2/messages.1', 'initially dir2/messages.1');
15567c478bd9Sstevel@tonic-gate	set_file('dir2/messages.2', 'initially dir2/messages.2');
15577c478bd9Sstevel@tonic-gate	set_file('dir2/messages.3', 'initially dir2/messages.3');
15587c478bd9Sstevel@tonic-gate
15597c478bd9Sstevel@tonic-gate	set_file('logadm.conf', <<"EOF");
15607c478bd9Sstevel@tonic-gatedir1/syslog -C 8 -s 30b
15617c478bd9Sstevel@tonic-gatedir2/messages -C 4 -s 30b
15627c478bd9Sstevel@tonic-gateEOF
15637c478bd9Sstevel@tonic-gate
15647c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
1565e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
15667c478bd9Sstevel@tonic-gate[ -s std.out ] && exit 1
15677c478bd9Sstevel@tonic-gate[ -f dir1/syslog ] || exit 1
15687c478bd9Sstevel@tonic-gate[ -s dir1/syslog ] && exit 1
15697c478bd9Sstevel@tonic-gate[ -f dir1/syslog.0 ] || exit 1
15707c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslogXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
15717c478bd9Sstevel@tonic-gate[ -f dir1/syslog.1 ] || exit 1
15727c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
15737c478bd9Sstevel@tonic-gate[ -f dir1/syslog.2 ] || exit 1
15747c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
15757c478bd9Sstevel@tonic-gate[ -f dir1/syslog.3 ] || exit 1
15767c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
15777c478bd9Sstevel@tonic-gate[ -f dir1/syslog.4 ] || exit 1
15787c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
15797c478bd9Sstevel@tonic-gate[ -f dir1/syslog.5 ] || exit 1
15807c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
15817c478bd9Sstevel@tonic-gate[ -f dir1/syslog.6 ] || exit 1
15827c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
15837c478bd9Sstevel@tonic-gate[ -f dir1/syslog.7 ] || exit 1
15847c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
15857c478bd9Sstevel@tonic-gate[ -f dir1/syslog.8 ] && exit 1
15867c478bd9Sstevel@tonic-gate
15877c478bd9Sstevel@tonic-gate[ -f dir2/messages ] || exit 1
15887c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages" = "x`/bin/cat dir2/messages`" ] || exit 1
15897c478bd9Sstevel@tonic-gate[ -f dir2/messages.0 ] || exit 1
15907c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.0`" ] || exit 1
15917c478bd9Sstevel@tonic-gate[ -f dir2/messages.1 ] || exit 1
15927c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.1`" ] || exit 1
15937c478bd9Sstevel@tonic-gate[ -f dir2/messages.2 ] || exit 1
15947c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages.2" = "x`/bin/cat dir2/messages.2`" ] || exit 1
15957c478bd9Sstevel@tonic-gate[ -f dir2/messages.3 ] || exit 1
15967c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages.3" = "x`/bin/cat dir2/messages.3`" ] || exit 1
15977c478bd9Sstevel@tonic-gate[ -f dir2/messages.4 ] && exit 1
15987c478bd9Sstevel@tonic-gateexit 0
15997c478bd9Sstevel@tonic-gateEOF
16007c478bd9Sstevel@tonic-gate
16017c478bd9Sstevel@tonic-gate        set_file('runtest', <<"EOF");
16027c478bd9Sstevel@tonic-gate# test "logadm10"
16037c478bd9Sstevel@tonic-gate$envsetup
1604e9a193fcSJohn.Zolnowsky@Sun.COMexec $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err
16057c478bd9Sstevel@tonic-gateEOF
16067c478bd9Sstevel@tonic-gate}
16077c478bd9Sstevel@tonic-gate
16087c478bd9Sstevel@tonic-gate###########################################################################
16097c478bd9Sstevel@tonic-gate#
16107c478bd9Sstevel@tonic-gate#       logadm11 -- test of size-based expiration check
16117c478bd9Sstevel@tonic-gate#
16127c478bd9Sstevel@tonic-gate###########################################################################
16137c478bd9Sstevel@tonic-gatesub logadm11 {
16147c478bd9Sstevel@tonic-gate	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
16157c478bd9Sstevel@tonic-gate	set_file('dir1/syslog', 'initially dir1/syslog');
16167c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.0', 'initially dir1/syslog.0');
16177c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.1', 'initially dir1/syslog.1');
16187c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.2', 'initially dir1/syslog.2');
16197c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.3', 'initially dir1/syslog.3');
16207c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.4', 'initially dir1/syslog.4');
16217c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.5', 'initially dir1/syslog.5');
16227c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.6', 'initially dir1/syslog.6');
16237c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.7', 'initially dir1/syslog.7');
16247c478bd9Sstevel@tonic-gate	mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
16257c478bd9Sstevel@tonic-gate	set_file('dir2/messages', 'initially dir2/messages');
16267c478bd9Sstevel@tonic-gate	set_file('dir2/messages.0', 'initially dir2/messages.0');
16277c478bd9Sstevel@tonic-gate	set_file('dir2/messages.1', 'initially dir2/messages.1');
16287c478bd9Sstevel@tonic-gate	set_file('dir2/messages.2', 'initially dir2/messages.2');
16297c478bd9Sstevel@tonic-gate	set_file('dir2/messages.3', 'initially dir2/messages.3');
16307c478bd9Sstevel@tonic-gate
16317c478bd9Sstevel@tonic-gate	set_file('logadm.conf', <<"EOF");
16327c478bd9Sstevel@tonic-gatedir1/syslog -C 8 -s 30b -S 75b
16337c478bd9Sstevel@tonic-gatedir2/messages -C 4 -s 30b -S 75b
16347c478bd9Sstevel@tonic-gateEOF
16357c478bd9Sstevel@tonic-gate
16367c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
1637e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
16387c478bd9Sstevel@tonic-gate[ -s std.out ] && exit 1
16397c478bd9Sstevel@tonic-gate[ -f dir1/syslog ] || exit 1
16407c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog`" ] || exit 1
16417c478bd9Sstevel@tonic-gate[ -f dir1/syslog.0 ] || exit 1
16427c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
16437c478bd9Sstevel@tonic-gate[ -f dir1/syslog.1 ] || exit 1
16447c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
16457c478bd9Sstevel@tonic-gate[ -f dir1/syslog.2 ] || exit 1
16467c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
16477c478bd9Sstevel@tonic-gate[ -f dir1/syslog.3 ] && exit 1
16487c478bd9Sstevel@tonic-gate[ -f dir1/syslog.4 ] && exit 1
16497c478bd9Sstevel@tonic-gate[ -f dir1/syslog.5 ] && exit 1
16507c478bd9Sstevel@tonic-gate[ -f dir1/syslog.6 ] && exit 1
16517c478bd9Sstevel@tonic-gate[ -f dir1/syslog.7 ] && exit 1
16527c478bd9Sstevel@tonic-gate[ -f dir1/syslog.8 ] && exit 1
16537c478bd9Sstevel@tonic-gate
16547c478bd9Sstevel@tonic-gate[ -f dir2/messages ] || exit 1
16557c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages" = "x`/bin/cat dir2/messages`" ] || exit 1
16567c478bd9Sstevel@tonic-gate[ -f dir2/messages.0 ] || exit 1
16577c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.0`" ] || exit 1
16587c478bd9Sstevel@tonic-gate[ -f dir2/messages.1 ] || exit 1
16597c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.1`" ] || exit 1
16607c478bd9Sstevel@tonic-gate[ -f dir2/messages.2 ] || exit 1
16617c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages.2" = "x`/bin/cat dir2/messages.2`" ] || exit 1
16627c478bd9Sstevel@tonic-gate[ -f dir2/messages.3 ] && exit 1
16637c478bd9Sstevel@tonic-gate[ -f dir2/messages.4 ] && exit 1
16647c478bd9Sstevel@tonic-gateexit 0
16657c478bd9Sstevel@tonic-gateEOF
16667c478bd9Sstevel@tonic-gate
16677c478bd9Sstevel@tonic-gate        set_file('runtest', <<"EOF");
16687c478bd9Sstevel@tonic-gate# test "logadm11"
16697c478bd9Sstevel@tonic-gate$envsetup
1670e9a193fcSJohn.Zolnowsky@Sun.COMexec $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err
16717c478bd9Sstevel@tonic-gateEOF
16727c478bd9Sstevel@tonic-gate}
16737c478bd9Sstevel@tonic-gate
16747c478bd9Sstevel@tonic-gate###########################################################################
16757c478bd9Sstevel@tonic-gate#
16767c478bd9Sstevel@tonic-gate#	logadm12 -- ENOENT error path
16777c478bd9Sstevel@tonic-gate#
16787c478bd9Sstevel@tonic-gate###########################################################################
16797c478bd9Sstevel@tonic-gatesub logadm12 {
16807c478bd9Sstevel@tonic-gate	set_file('std.err.expect', <<'EOF');
16817c478bd9Sstevel@tonic-gatelogadm: Warning: logfile: No such file or directory
16827c478bd9Sstevel@tonic-gateEOF
16837c478bd9Sstevel@tonic-gate
16847c478bd9Sstevel@tonic-gate	set_file('checktest', <<"EOF");
16857c478bd9Sstevel@tonic-gate[ -s std.out ] && exit 1
1686e9a193fcSJohn.Zolnowsky@Sun.COMexec /bin/diff std.err.expect std.err
16877c478bd9Sstevel@tonic-gateEOF
16887c478bd9Sstevel@tonic-gate
16897c478bd9Sstevel@tonic-gate	set_file('runtest', <<"EOF");
16907c478bd9Sstevel@tonic-gate# test "logadm12"
16917c478bd9Sstevel@tonic-gate$envsetup
16927c478bd9Sstevel@tonic-gateexec $bindir/logadm -f /dev/null logfile >std.out 2>std.err
16937c478bd9Sstevel@tonic-gateEOF
16947c478bd9Sstevel@tonic-gate}
16957c478bd9Sstevel@tonic-gate
16967c478bd9Sstevel@tonic-gate###########################################################################
16977c478bd9Sstevel@tonic-gate#
16987c478bd9Sstevel@tonic-gate#	logadm13 -- ENOENT error path with -N flag
16997c478bd9Sstevel@tonic-gate#
17007c478bd9Sstevel@tonic-gate###########################################################################
17017c478bd9Sstevel@tonic-gatesub logadm13 {
17027c478bd9Sstevel@tonic-gate	set_file('checktest', <<"EOF");
1703e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
17047c478bd9Sstevel@tonic-gate[ -s std.out ] && exit 1
17057c478bd9Sstevel@tonic-gateexit 0
17067c478bd9Sstevel@tonic-gateEOF
17077c478bd9Sstevel@tonic-gate
17087c478bd9Sstevel@tonic-gate	set_file('runtest', <<"EOF");
17097c478bd9Sstevel@tonic-gate# test "logadm13"
17107c478bd9Sstevel@tonic-gate$envsetup
17117c478bd9Sstevel@tonic-gateexec $bindir/logadm -N -f /dev/null logfile >std.out 2>std.err
17127c478bd9Sstevel@tonic-gateEOF
17137c478bd9Sstevel@tonic-gate}
17147c478bd9Sstevel@tonic-gate
17157c478bd9Sstevel@tonic-gate###########################################################################
17167c478bd9Sstevel@tonic-gate#
17177c478bd9Sstevel@tonic-gate#       logadm14 -- test of -n and -v flags
17187c478bd9Sstevel@tonic-gate#
17197c478bd9Sstevel@tonic-gate###########################################################################
17207c478bd9Sstevel@tonic-gatesub logadm14 {
17217c478bd9Sstevel@tonic-gate	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
17227c478bd9Sstevel@tonic-gate	set_file('dir1/syslog', 'initially dir1/syslog');
17237c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.0', 'initially dir1/syslog.0');
17247c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.1', 'initially dir1/syslog.1');
17257c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.2', 'initially dir1/syslog.2');
17267c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.3', 'initially dir1/syslog.3');
17277c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.4', 'initially dir1/syslog.4');
17287c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.5', 'initially dir1/syslog.5');
17297c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.6', 'initially dir1/syslog.6');
17307c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.7', 'initially dir1/syslog.7');
17317c478bd9Sstevel@tonic-gate	mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
17327c478bd9Sstevel@tonic-gate	set_file('dir2/messages', 'initially dir2/messages');
17337c478bd9Sstevel@tonic-gate	set_file('dir2/messages.0', 'initially dir2/messages.0');
17347c478bd9Sstevel@tonic-gate	set_file('dir2/messages.1', 'initially dir2/messages.1');
17357c478bd9Sstevel@tonic-gate	set_file('dir2/messages.2', 'initially dir2/messages.2');
17367c478bd9Sstevel@tonic-gate	set_file('dir2/messages.3', 'initially dir2/messages.3');
17377c478bd9Sstevel@tonic-gate
17387c478bd9Sstevel@tonic-gate	set_file('logadm.conf', <<'EOF');
17397c478bd9Sstevel@tonic-gate#
17407c478bd9Sstevel@tonic-gate# logadm.conf
17417c478bd9Sstevel@tonic-gate#
17427c478bd9Sstevel@tonic-gate# Default settings for system log file management.
1743*bbf21555SRichard Lowe# The -w option to logadm(8) is the preferred way to write to this file,
17447c478bd9Sstevel@tonic-gate# but if you do edit it by hand, use "logadm -V" to check it for errors.
17457c478bd9Sstevel@tonic-gate# but if you do edit it by hand, use "logadm -V" to check it for errors.
17467c478bd9Sstevel@tonic-gate#
17477c478bd9Sstevel@tonic-gate# The format of lines in this file is:
17487c478bd9Sstevel@tonic-gate#       <logname> <options>
17497c478bd9Sstevel@tonic-gate# For each logname listed here, the default options to logadm
17507c478bd9Sstevel@tonic-gate# are given.  Options given on the logadm command line override
17517c478bd9Sstevel@tonic-gate# the defaults contained in this file.
17527c478bd9Sstevel@tonic-gate#
17537c478bd9Sstevel@tonic-gate# logadm typically runs early every morning via an entry in
17547c478bd9Sstevel@tonic-gate# root's crontab (see crontab(1)).
17557c478bd9Sstevel@tonic-gate#
1756fdaa2824SBryan Cantrilldir1/syslog -C 8 -a 'echo kill -HUP `cat /var/run/*syslog*pid` >> cmd.out'
1757fdaa2824SBryan Cantrilldir2/messages -C 4 -a 'echo kill -HUP `cat /var/run/*syslog*pid` >> cmd.out'
17587c478bd9Sstevel@tonic-gate#
1759*bbf21555SRichard Lowe# The entry below is used by turnacct(8)
17607c478bd9Sstevel@tonic-gate#
17617c478bd9Sstevel@tonic-gate/var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
17627c478bd9Sstevel@tonic-gateEOF
17637c478bd9Sstevel@tonic-gate
17647c478bd9Sstevel@tonic-gate	$gid = $);
17657c478bd9Sstevel@tonic-gate	$gid =~ s/ .*//;
17667c478bd9Sstevel@tonic-gate	set_file('grep.out.expect', <<'EOF'.<<"EOF".<<'EOF'.<<"EOF".<<'EOF');
17677c478bd9Sstevel@tonic-gate# loading logadm.conf
17687c478bd9Sstevel@tonic-gate# processing logname: dir1/syslog
17697c478bd9Sstevel@tonic-gate#     using default rotate rules: -s1b -p1w
17707c478bd9Sstevel@tonic-gate#     using default template: $file.$n
17717c478bd9Sstevel@tonic-gatemkdir -p dir1 # verify directory exists
17727c478bd9Sstevel@tonic-gatemv -f dir1/syslog.7 dir1/syslog.8 # rotate log file
17737c478bd9Sstevel@tonic-gatemkdir -p dir1 # verify directory exists
17747c478bd9Sstevel@tonic-gatemv -f dir1/syslog.6 dir1/syslog.7 # rotate log file
17757c478bd9Sstevel@tonic-gatemkdir -p dir1 # verify directory exists
17767c478bd9Sstevel@tonic-gatemv -f dir1/syslog.5 dir1/syslog.6 # rotate log file
17777c478bd9Sstevel@tonic-gatemkdir -p dir1 # verify directory exists
17787c478bd9Sstevel@tonic-gatemv -f dir1/syslog.4 dir1/syslog.5 # rotate log file
17797c478bd9Sstevel@tonic-gatemkdir -p dir1 # verify directory exists
17807c478bd9Sstevel@tonic-gatemv -f dir1/syslog.3 dir1/syslog.4 # rotate log file
17817c478bd9Sstevel@tonic-gatemkdir -p dir1 # verify directory exists
17827c478bd9Sstevel@tonic-gatemv -f dir1/syslog.2 dir1/syslog.3 # rotate log file
17837c478bd9Sstevel@tonic-gatemkdir -p dir1 # verify directory exists
17847c478bd9Sstevel@tonic-gatemv -f dir1/syslog.1 dir1/syslog.2 # rotate log file
17857c478bd9Sstevel@tonic-gatemkdir -p dir1 # verify directory exists
17867c478bd9Sstevel@tonic-gatemv -f dir1/syslog.0 dir1/syslog.1 # rotate log file
17877c478bd9Sstevel@tonic-gatemkdir -p dir1 # verify directory exists
17887c478bd9Sstevel@tonic-gatemv -f dir1/syslog dir1/syslog.0 # rotate log file
17897c478bd9Sstevel@tonic-gatetouch dir1/syslog
17907c478bd9Sstevel@tonic-gateEOF
17917c478bd9Sstevel@tonic-gatechown $>:$gid dir1/syslog
17927c478bd9Sstevel@tonic-gateEOF
17937c478bd9Sstevel@tonic-gatechmod 664 dir1/syslog
17947c478bd9Sstevel@tonic-gate# processing logname: dir2/messages
17957c478bd9Sstevel@tonic-gate#     using default rotate rules: -s1b -p1w
17967c478bd9Sstevel@tonic-gate#     using default template: $file.$n
17977c478bd9Sstevel@tonic-gatemkdir -p dir2 # verify directory exists
17987c478bd9Sstevel@tonic-gatemv -f dir2/messages.3 dir2/messages.4 # rotate log file
17997c478bd9Sstevel@tonic-gatemkdir -p dir2 # verify directory exists
18007c478bd9Sstevel@tonic-gatemv -f dir2/messages.2 dir2/messages.3 # rotate log file
18017c478bd9Sstevel@tonic-gatemkdir -p dir2 # verify directory exists
18027c478bd9Sstevel@tonic-gatemv -f dir2/messages.1 dir2/messages.2 # rotate log file
18037c478bd9Sstevel@tonic-gatemkdir -p dir2 # verify directory exists
18047c478bd9Sstevel@tonic-gatemv -f dir2/messages.0 dir2/messages.1 # rotate log file
18057c478bd9Sstevel@tonic-gatemkdir -p dir2 # verify directory exists
18067c478bd9Sstevel@tonic-gatemv -f dir2/messages dir2/messages.0 # rotate log file
18077c478bd9Sstevel@tonic-gatetouch dir2/messages
18087c478bd9Sstevel@tonic-gateEOF
18097c478bd9Sstevel@tonic-gatechown $>:$gid dir2/messages
18107c478bd9Sstevel@tonic-gateEOF
18117c478bd9Sstevel@tonic-gatechmod 664 dir2/messages
18127c478bd9Sstevel@tonic-gate# processing logname: /var/adm/pacct
18137c478bd9Sstevel@tonic-gate#     using default template: $file.$n
1814fdaa2824SBryan Cantrillsh -c echo kill -HUP `cat /var/run/*syslog*pid` >> cmd.out # -a cmd
1815e9a193fcSJohn.Zolnowsky@Sun.COM# logadm.conf and logadm.timestamps unchanged
18167c478bd9Sstevel@tonic-gateEOF
18177c478bd9Sstevel@tonic-gate
18187c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
1819e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
18207c478bd9Sstevel@tonic-gate[ -f std.out ] || exit 1
18217c478bd9Sstevel@tonic-gate[ -f dir1/syslog ] || exit 1
18227c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog`" ] || exit 1
18237c478bd9Sstevel@tonic-gate[ -f dir1/syslog.0 ] || exit 1
18247c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
18257c478bd9Sstevel@tonic-gate[ -f dir1/syslog.1 ] || exit 1
18267c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
18277c478bd9Sstevel@tonic-gate[ -f dir1/syslog.2 ] || exit 1
18287c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
18297c478bd9Sstevel@tonic-gate[ -f dir1/syslog.3 ] || exit 1
18307c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
18317c478bd9Sstevel@tonic-gate[ -f dir1/syslog.4 ] || exit 1
18327c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
18337c478bd9Sstevel@tonic-gate[ -f dir1/syslog.5 ] || exit 1
18347c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
18357c478bd9Sstevel@tonic-gate[ -f dir1/syslog.6 ] || exit 1
18367c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
18377c478bd9Sstevel@tonic-gate[ -f dir1/syslog.7 ] || exit 1
18387c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.7" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
18397c478bd9Sstevel@tonic-gate[ -f dir1/syslog.8 ] && exit 1
18407c478bd9Sstevel@tonic-gate
18417c478bd9Sstevel@tonic-gate[ -f dir2/messages ] || exit 1
18427c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages" = "x`/bin/cat dir2/messages`" ] || exit 1
18437c478bd9Sstevel@tonic-gate[ -f dir2/messages.0 ] || exit 1
18447c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.0`" ] || exit 1
18457c478bd9Sstevel@tonic-gate[ -f dir2/messages.1 ] || exit 1
18467c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.1`" ] || exit 1
18477c478bd9Sstevel@tonic-gate[ -f dir2/messages.2 ] || exit 1
18487c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages.2" = "x`/bin/cat dir2/messages.2`" ] || exit 1
18497c478bd9Sstevel@tonic-gate[ -f dir2/messages.3 ] || exit 1
18507c478bd9Sstevel@tonic-gate[ "xinitially dir2/messages.3" = "x`/bin/cat dir2/messages.3`" ] || exit 1
18517c478bd9Sstevel@tonic-gate[ -f dir2/messages.4 ] && exit 1
18527c478bd9Sstevel@tonic-gate/bin/grep -v 'recording rotation date' std.out > grep.out
1853e9a193fcSJohn.Zolnowsky@Sun.COMexec /bin/diff grep.out.expect grep.out
18547c478bd9Sstevel@tonic-gateEOF
18557c478bd9Sstevel@tonic-gate
18567c478bd9Sstevel@tonic-gate        set_file('runtest', <<"EOF");
18577c478bd9Sstevel@tonic-gate# test "logadm14"
18587c478bd9Sstevel@tonic-gate$envsetup
1859e9a193fcSJohn.Zolnowsky@Sun.COMexec $bindir/logadm -nv -f logadm.conf -F logadm.timestamps >std.out 2>std.err
18607c478bd9Sstevel@tonic-gateEOF
18617c478bd9Sstevel@tonic-gate}
18627c478bd9Sstevel@tonic-gate
18637c478bd9Sstevel@tonic-gate###########################################################################
18647c478bd9Sstevel@tonic-gate#
18657c478bd9Sstevel@tonic-gate#	logadm15 -- test of -T
18667c478bd9Sstevel@tonic-gate#
18677c478bd9Sstevel@tonic-gate###########################################################################
18687c478bd9Sstevel@tonic-gatesub logadm15 {
18697c478bd9Sstevel@tonic-gate	set_file('logfile', '');
18707c478bd9Sstevel@tonic-gate	set_file('logfile.0', 'initially logfile.0');
18717c478bd9Sstevel@tonic-gate	set_file('logfile.1', 'initially logfile.1');
18727c478bd9Sstevel@tonic-gate	set_file('logfile.2', 'initially logfile.2');
18737c478bd9Sstevel@tonic-gate	set_file('logfile.3', 'initially logfile.3');
18747c478bd9Sstevel@tonic-gate	set_file('logfile.4', 'initially logfile.4');
18757c478bd9Sstevel@tonic-gate	set_file('logfile.5', 'initially logfile.5');
18767c478bd9Sstevel@tonic-gate	set_file('logfile.6', 'initially logfile.6');
18777c478bd9Sstevel@tonic-gate	set_file('logfile.7', 'initially logfile.7');
18787c478bd9Sstevel@tonic-gate	set_file('logfile.8', 'initially logfile.8');
18797c478bd9Sstevel@tonic-gate	set_file('logfile.9', 'initially logfile.9');
18807c478bd9Sstevel@tonic-gate
18817c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
1882e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
18837c478bd9Sstevel@tonic-gate[ -s std.out ] && exit 1
18847c478bd9Sstevel@tonic-gate[ -f logfile ] || exit 1
18857c478bd9Sstevel@tonic-gate[ "x" = "x`/bin/cat logfile`" ] || exit 1
18867c478bd9Sstevel@tonic-gate[ -f logfile.0 ] || exit 1
18877c478bd9Sstevel@tonic-gate[ "xinitially logfile.0" = "x`/bin/cat logfile.0`" ] || exit 1
18887c478bd9Sstevel@tonic-gate[ -f logfile.1 ] || exit 1
18897c478bd9Sstevel@tonic-gate[ "xinitially logfile.1" = "x`/bin/cat logfile.1`" ] || exit 1
18907c478bd9Sstevel@tonic-gate[ -f logfile.2 ] || exit 1
18917c478bd9Sstevel@tonic-gate[ "xinitially logfile.2" = "x`/bin/cat logfile.2`" ] || exit 1
18927c478bd9Sstevel@tonic-gate[ -f logfile.3 ] && exit 1
18937c478bd9Sstevel@tonic-gate[ -f logfile.4 ] || exit 1
18947c478bd9Sstevel@tonic-gate[ "xinitially logfile.4" = "x`/bin/cat logfile.4`" ] || exit 1
18957c478bd9Sstevel@tonic-gate[ -f logfile.5 ] && exit 1
18967c478bd9Sstevel@tonic-gate[ -f logfile.6 ] || exit 1
18977c478bd9Sstevel@tonic-gate[ "xinitially logfile.6" = "x`/bin/cat logfile.6`" ] || exit 1
18987c478bd9Sstevel@tonic-gate[ -f logfile.7 ] && exit 1
18997c478bd9Sstevel@tonic-gate[ -f logfile.8 ] || exit 1
19007c478bd9Sstevel@tonic-gate[ "xinitially logfile.8" = "x`/bin/cat logfile.8`" ] || exit 1
19017c478bd9Sstevel@tonic-gate[ -f logfile.9 ] && exit 1
19027c478bd9Sstevel@tonic-gate[ -f logfile.10 ] && exit 1
19037c478bd9Sstevel@tonic-gateexit 0
19047c478bd9Sstevel@tonic-gateEOF
19057c478bd9Sstevel@tonic-gate
19067c478bd9Sstevel@tonic-gate	set_file('runtest', <<"EOF");
19077c478bd9Sstevel@tonic-gate# test "logadm15"
19087c478bd9Sstevel@tonic-gate$envsetup
19097c478bd9Sstevel@tonic-gateexec $bindir/logadm -f /dev/null logfile -C1 -T '*.[13579]'>std.out 2>std.err
19107c478bd9Sstevel@tonic-gateEOF
19117c478bd9Sstevel@tonic-gate}
19127c478bd9Sstevel@tonic-gate
19137c478bd9Sstevel@tonic-gate###########################################################################
19147c478bd9Sstevel@tonic-gate#
19157c478bd9Sstevel@tonic-gate#	logadm16 -- test of -h
19167c478bd9Sstevel@tonic-gate#
19177c478bd9Sstevel@tonic-gate###########################################################################
19187c478bd9Sstevel@tonic-gatesub logadm16 {
19197c478bd9Sstevel@tonic-gate	set_file('std.err.expect', <<'EOF');
19207c478bd9Sstevel@tonic-gateUsage: logadm [options]
19217c478bd9Sstevel@tonic-gate       (processes all entries in /etc/logadm.conf or conffile given by -f)
19227c478bd9Sstevel@tonic-gate   or: logadm [options] logname...
19237c478bd9Sstevel@tonic-gate       (processes the given lognames)
19247c478bd9Sstevel@tonic-gate
19257c478bd9Sstevel@tonic-gateGeneral options:
19267c478bd9Sstevel@tonic-gate        -e mailaddr     mail errors to given address
1927e9a193fcSJohn.Zolnowsky@Sun.COM        -F timestamps   use timestamps instead of /var/logadm/timestamps
19287c478bd9Sstevel@tonic-gate        -f conffile     use conffile instead of /etc/logadm.conf
19297c478bd9Sstevel@tonic-gate        -h              display help
19307c478bd9Sstevel@tonic-gate        -N              not an error if log file nonexistent
19317c478bd9Sstevel@tonic-gate        -n              show actions, don't perform them
19327c478bd9Sstevel@tonic-gate        -r              remove logname entry from conffile
19337c478bd9Sstevel@tonic-gate        -V              ensure conffile entries exist, correct
19347c478bd9Sstevel@tonic-gate        -v              print info about actions happening
19357c478bd9Sstevel@tonic-gate        -w entryname    write entry to config file
19367c478bd9Sstevel@tonic-gate
19377c478bd9Sstevel@tonic-gateOptions which control when a logfile is rotated:
19387c478bd9Sstevel@tonic-gate(default is: -s1b -p1w if no -s or -p)
19397c478bd9Sstevel@tonic-gate        -p period       only rotate if period passed since last rotate
19407c478bd9Sstevel@tonic-gate        -P timestamp    used to store rotation date in conffile
19417c478bd9Sstevel@tonic-gate        -s size         only rotate if given size or greater
19427c478bd9Sstevel@tonic-gate
19437c478bd9Sstevel@tonic-gateOptions which control how a logfile is rotated:
19447c478bd9Sstevel@tonic-gate(default is: -t '$file.$n', owner/group/mode taken from log file)
19457c478bd9Sstevel@tonic-gate        -a cmd          execute cmd after taking actions
19467c478bd9Sstevel@tonic-gate        -b cmd          execute cmd before taking actions
19477c478bd9Sstevel@tonic-gate        -c              copy & truncate logfile, don't rename
19487c478bd9Sstevel@tonic-gate        -g group        new empty log file group
1949636deb66Sgm        -l              rotate log file with local time rather than UTC
19507c478bd9Sstevel@tonic-gate        -m mode         new empty log file mode
19517c478bd9Sstevel@tonic-gate        -M cmd          execute cmd to rotate the log file
19527c478bd9Sstevel@tonic-gate        -o owner        new empty log file owner
19537c478bd9Sstevel@tonic-gate        -R cmd          run cmd on file after rotate
19547c478bd9Sstevel@tonic-gate        -t template     template for naming old logs
19557c478bd9Sstevel@tonic-gate        -z count        gzip old logs except most recent count
19567c478bd9Sstevel@tonic-gate
19577c478bd9Sstevel@tonic-gateOptions which control the expiration of old logfiles:
19587c478bd9Sstevel@tonic-gate(default is: -C10 if no -A, -C, or -S)
19597c478bd9Sstevel@tonic-gate        -A age          expire logs older than age
19607c478bd9Sstevel@tonic-gate        -C count        expire old logs until count remain
19617c478bd9Sstevel@tonic-gate        -E cmd          run cmd on file to expire
19627c478bd9Sstevel@tonic-gate        -S size         expire until space used is below size
19637c478bd9Sstevel@tonic-gate        -T pattern      pattern for finding old logs
19647c478bd9Sstevel@tonic-gateEOF
19657c478bd9Sstevel@tonic-gate
19667c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
19677c478bd9Sstevel@tonic-gate[ -s std.out ] && exit 1
1968e9a193fcSJohn.Zolnowsky@Sun.COMexec /bin/diff std.err.expect std.err
19697c478bd9Sstevel@tonic-gateEOF
19707c478bd9Sstevel@tonic-gate
19717c478bd9Sstevel@tonic-gate	set_file('runtest', <<"EOF");
19727c478bd9Sstevel@tonic-gate# test "logadm16"
19737c478bd9Sstevel@tonic-gate$envsetup
19747c478bd9Sstevel@tonic-gateexec $bindir/logadm -h >std.out 2>std.err
19757c478bd9Sstevel@tonic-gateEOF
19767c478bd9Sstevel@tonic-gate}
19777c478bd9Sstevel@tonic-gate
19787c478bd9Sstevel@tonic-gate###########################################################################
19797c478bd9Sstevel@tonic-gate#
19807c478bd9Sstevel@tonic-gate#       logadm17 -- test that mkdir -p happens as necessary
19817c478bd9Sstevel@tonic-gate#
19827c478bd9Sstevel@tonic-gate###########################################################################
19837c478bd9Sstevel@tonic-gatesub logadm17 {
19847c478bd9Sstevel@tonic-gate	set_file('logfile', 'initially logfile');
19857c478bd9Sstevel@tonic-gate
19867c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
1987e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
19887c478bd9Sstevel@tonic-gate[ -s std.out ] && exit 1
19897c478bd9Sstevel@tonic-gate[ -f dir1/dir2/logfile ] || exit 1
19907c478bd9Sstevel@tonic-gate[ -f logfile ] || exit 1
19917c478bd9Sstevel@tonic-gate[ "xinitially logfile" = "x`/bin/cat dir1/dir2/logfile`" ] || exit 1
19927c478bd9Sstevel@tonic-gateexit 0
19937c478bd9Sstevel@tonic-gateEOF
19947c478bd9Sstevel@tonic-gate
19957c478bd9Sstevel@tonic-gate        set_file('runtest', <<"EOF");
19967c478bd9Sstevel@tonic-gate# test "logadm17"
19977c478bd9Sstevel@tonic-gate$envsetup
19987c478bd9Sstevel@tonic-gateexec $bindir/logadm -f /dev/null -t 'dir1/dir2/\$basename' logfile -p now >std.out 2>std.err
19997c478bd9Sstevel@tonic-gateEOF
20007c478bd9Sstevel@tonic-gate}
20017c478bd9Sstevel@tonic-gate
20027c478bd9Sstevel@tonic-gate###########################################################################
20037c478bd9Sstevel@tonic-gate#
20047c478bd9Sstevel@tonic-gate#       logadm18 -- test of -M option
20057c478bd9Sstevel@tonic-gate#
20067c478bd9Sstevel@tonic-gate###########################################################################
20077c478bd9Sstevel@tonic-gatesub logadm18 {
20087c478bd9Sstevel@tonic-gate	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
20097c478bd9Sstevel@tonic-gate	set_file('dir1/syslog', 'initially dir1/syslog');
20107c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.0', 'initially dir1/syslog.0');
20117c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.1', 'initially dir1/syslog.1');
20127c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.2', 'initially dir1/syslog.2');
20137c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.3', 'initially dir1/syslog.3');
20147c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.4', 'initially dir1/syslog.4');
20157c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.5', 'initially dir1/syslog.5');
20167c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.6', 'initially dir1/syslog.6');
20177c478bd9Sstevel@tonic-gate	set_file('dir1/syslog.7', 'initially dir1/syslog.7');
20187c478bd9Sstevel@tonic-gate
20197c478bd9Sstevel@tonic-gate	set_file('logadm.conf', <<"EOF");
20207c478bd9Sstevel@tonic-gatedir1/syslog -C 8 -s 1b -M '/bin/tr [a-z] [A-Z] < \$file > \$nfile; /bin/rm -f \$file'
20217c478bd9Sstevel@tonic-gateEOF
20227c478bd9Sstevel@tonic-gate
20237c478bd9Sstevel@tonic-gate	set_file('checktest', <<'EOF');
2024e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
20257c478bd9Sstevel@tonic-gate[ -s std.out ] && exit 1
20267c478bd9Sstevel@tonic-gate[ -f dir1/syslog ] || exit 1
20277c478bd9Sstevel@tonic-gate[ -s dir1/syslog ] && exit 1
20287c478bd9Sstevel@tonic-gate[ -f dir1/syslog.0 ] || exit 1
20297c478bd9Sstevel@tonic-gate[ "xINITIALLY DIR1/SYSLOG" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
20307c478bd9Sstevel@tonic-gate[ -f dir1/syslog.1 ] || exit 1
20317c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
20327c478bd9Sstevel@tonic-gate[ -f dir1/syslog.2 ] || exit 1
20337c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
20347c478bd9Sstevel@tonic-gate[ -f dir1/syslog.3 ] || exit 1
20357c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
20367c478bd9Sstevel@tonic-gate[ -f dir1/syslog.4 ] || exit 1
20377c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
20387c478bd9Sstevel@tonic-gate[ -f dir1/syslog.5 ] || exit 1
20397c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
20407c478bd9Sstevel@tonic-gate[ -f dir1/syslog.6 ] || exit 1
20417c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
20427c478bd9Sstevel@tonic-gate[ -f dir1/syslog.7 ] || exit 1
20437c478bd9Sstevel@tonic-gate[ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
20447c478bd9Sstevel@tonic-gate[ -f dir1/syslog.8 ] && exit 1
20457c478bd9Sstevel@tonic-gate
20467c478bd9Sstevel@tonic-gateexit 0
20477c478bd9Sstevel@tonic-gateEOF
20487c478bd9Sstevel@tonic-gate
20497c478bd9Sstevel@tonic-gate        set_file('runtest', <<"EOF");
20507c478bd9Sstevel@tonic-gate# test "logadm18"
20517c478bd9Sstevel@tonic-gate$envsetup
2052e9a193fcSJohn.Zolnowsky@Sun.COMexec $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err
20537c478bd9Sstevel@tonic-gateEOF
20547c478bd9Sstevel@tonic-gate}
2055636deb66Sgm
2056636deb66Sgm#############################################################################
2057636deb66Sgm#
2058636deb66Sgm#         logadm19 -- test of  -l
2059636deb66Sgm#
2060636deb66Sgm#############################################################################
2061636deb66Sgmsub logadm19 {
2062636deb66Sgm        set_file('logfile', 'initially logfile');
2063636deb66Sgm
2064636deb66Sgm        set_file('checktest', <<'EOF');
2065e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] && { cat std.err; exit 1; }
2066636deb66Sgm[ -s std.out ] && exit 1
2067636deb66Sgm[ -s logfile ] && exit 1
2068636deb66SgmTZ= export TZ
2069636deb66Sgmd=`/bin/date +\%d\%H\%M`
2070636deb66Sgm[ -f logfile.$d ] || exit 1
2071636deb66Sgm[ "xinitially logfile" = "x`/bin/cat logfile.$d`" ] || exit 1
2072636deb66Sgmexit 0
2073636deb66SgmEOF
2074636deb66Sgm
2075636deb66Sgm        set_file('runtest', <<"EOF");
2076e9a193fcSJohn.Zolnowsky@Sun.COM# test "logadm19"
2077636deb66Sgm$envsetup
2078636deb66Sgmexec $bindir/logadm -f /dev/null -l -p now logfile -t '\$file.\%d\%H\%M' >std.out 2>std.err
2079636deb66SgmEOF
2080636deb66Sgm}
2081e9a193fcSJohn.Zolnowsky@Sun.COM
2082e9a193fcSJohn.Zolnowsky@Sun.COM#############################################################################
2083e9a193fcSJohn.Zolnowsky@Sun.COM#
2084e9a193fcSJohn.Zolnowsky@Sun.COM#         logadm20 -- test of unquotables/error handling
2085e9a193fcSJohn.Zolnowsky@Sun.COM#
2086e9a193fcSJohn.Zolnowsky@Sun.COM#############################################################################
2087e9a193fcSJohn.Zolnowsky@Sun.COMsub logadm20 {
2088e9a193fcSJohn.Zolnowsky@Sun.COM	set_file('logadm.conf', <<'EOF');
2089e9a193fcSJohn.Zolnowsky@Sun.COM# non-trivial entry
2090fdaa2824SBryan Cantrill/var/log/syslog -C 8 -a 'kill -HUP `cat /var/run/*syslog*pid`'
2091e9a193fcSJohn.Zolnowsky@Sun.COMEOF
2092e9a193fcSJohn.Zolnowsky@Sun.COM
2093e9a193fcSJohn.Zolnowsky@Sun.COM	set_file('std.err.expect', <<'EOF');
2094e9a193fcSJohn.Zolnowsky@Sun.COMlogadm: Error: Can't protect quotes in </bin/echo "She can't take anymore, Cap'n!">
2095e9a193fcSJohn.Zolnowsky@Sun.COMlogadm: Error: unsafe to update configuration file or timestamps
2096e9a193fcSJohn.Zolnowsky@Sun.COMlogadm: Error: bailing out due to command line errors
2097e9a193fcSJohn.Zolnowsky@Sun.COMUse "logadm -h" for help.
2098e9a193fcSJohn.Zolnowsky@Sun.COMexit=1
2099e9a193fcSJohn.Zolnowsky@Sun.COMEOF
2100e9a193fcSJohn.Zolnowsky@Sun.COM
2101e9a193fcSJohn.Zolnowsky@Sun.COM        set_file('checktest', <<'EOF');
2102e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.err ] || exit 1
2103e9a193fcSJohn.Zolnowsky@Sun.COM[ -s std.out ] && exit 1
2104e9a193fcSJohn.Zolnowsky@Sun.COM[ -f logadm.conf????? ] && exit 1
2105e9a193fcSJohn.Zolnowsky@Sun.COM[ -f logadm.timestamps????? ] && exit 1
2106e9a193fcSJohn.Zolnowsky@Sun.COMexec /bin/diff std.err.expect std.err
2107e9a193fcSJohn.Zolnowsky@Sun.COMEOF
2108e9a193fcSJohn.Zolnowsky@Sun.COM
2109e9a193fcSJohn.Zolnowsky@Sun.COM        set_file('runtest', <<"EOF");
2110e9a193fcSJohn.Zolnowsky@Sun.COM# test "logadm20"
2111e9a193fcSJohn.Zolnowsky@Sun.COM$envsetup
2112e9a193fcSJohn.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
2113e9a193fcSJohn.Zolnowsky@Sun.COMecho exit=\$? >>std.err
2114e9a193fcSJohn.Zolnowsky@Sun.COMEOF
2115e9a193fcSJohn.Zolnowsky@Sun.COM}
21167ea02786SBryan Cantrill
21177ea02786SBryan Cantrill#############################################################################
21187ea02786SBryan Cantrill#
21197ea02786SBryan Cantrill#         logadm21 -- test of busted configuration file
21207ea02786SBryan Cantrill#
21217ea02786SBryan Cantrill#############################################################################
21227ea02786SBryan Cantrillsub logadm21 {
21237ea02786SBryan Cantrill	set_file('logadm.conf', <<'EOF');
21247ea02786SBryan Cantrillpoop
21257ea02786SBryan CantrillEOF
21267ea02786SBryan Cantrill	set_file('checktest', <<'EOF');
21277ea02786SBryan Cantrill[ -s std.err ] || exit 1
21287ea02786SBryan Cantrillgrep Warning std.err > /dev/null
21297ea02786SBryan CantrillEOF
21307ea02786SBryan Cantrill
21317ea02786SBryan Cantrill        set_file('runtest', <<"EOF");
21327ea02786SBryan Cantrill# test "logadm21"
21337ea02786SBryan Cantrill$envsetup
2134e911f249SSebastian Wiedenroth$bindir/logadm -f logadm.conf -F /dev/null 2>std.err
21357ea02786SBryan Cantrillexit 0
21367ea02786SBryan CantrillEOF
21377ea02786SBryan Cantrill}
2138e911f249SSebastian Wiedenroth
2139e911f249SSebastian Wiedenroth#############################################################################
2140e911f249SSebastian Wiedenroth#
2141e911f249SSebastian Wiedenroth#         logadm22 - test for keeping timestamps in timestamps file on -w
2142e911f249SSebastian Wiedenroth#
2143e911f249SSebastian Wiedenroth#############################################################################
2144e911f249SSebastian Wiedenroth
2145e911f249SSebastian Wiedenrothsub logadm22 {
2146e911f249SSebastian Wiedenroth	set_file('logadm.conf', <<'EOF');
2147e911f249SSebastian Wiedenrothwildcard_test -A 3d dir1/*.log
2148e911f249SSebastian Wiedenrothregular_test -A 3d dir2/test.log
2149e911f249SSebastian WiedenrothEOF
2150e911f249SSebastian Wiedenroth
2151e911f249SSebastian Wiedenrothset_file('logadm.conf.expect', <<'EOF');
2152e911f249SSebastian Wiedenrothwildcard_test -A 3d dir1/*.log
2153e911f249SSebastian Wiedenrothregular_test -A 3d dir2/test.log
2154e911f249SSebastian Wiedenrothdir3/test.log -A 3d
2155e911f249SSebastian WiedenrothEOF
2156e911f249SSebastian Wiedenroth
2157e911f249SSebastian Wiedenroth	set_file('logadm.timestamps', <<'EOF');
2158*bbf21555SRichard Lowe# This file holds internal data for logadm(8).
2159e911f249SSebastian Wiedenroth# Do not edit.
2160e911f249SSebastian Wiedenrothdir1/foo.log -P 'Thu Nov  1 16:56:42 2001'
2161e911f249SSebastian Wiedenrothdir2/test.log -P 'Thu Nov  1 16:56:42 2001'
2162e911f249SSebastian WiedenrothEOF
2163e911f249SSebastian Wiedenroth	system("/bin/cp logadm.timestamps logadm.timestamps.expect");
2164e911f249SSebastian Wiedenroth
2165e911f249SSebastian Wiedenroth	set_file('checktest', <<'EOF');
2166e911f249SSebastian Wiedenroth[ -s std.err ] && { cat std.err; exit 1; }
2167e911f249SSebastian Wiedenroth/bin/diff logadm.conf.expect logadm.conf || exit 1
2168e911f249SSebastian Wiedenroth/bin/diff logadm.timestamps.expect logadm.timestamps || exit 1
2169e911f249SSebastian WiedenrothEOF
2170e911f249SSebastian Wiedenroth
2171e911f249SSebastian Wiedenroth	set_file('runtest', <<"EOF");
2172e911f249SSebastian Wiedenroth# test "logadm22"
2173e911f249SSebastian Wiedenroth$envsetup
2174e911f249SSebastian Wiedenroth$bindir/logadm -f logadm.conf -F logadm.timestamps -w dir3/test.log -A 3d 2>std.err
2175e911f249SSebastian Wiedenrothexit 0
2176e911f249SSebastian WiedenrothEOF
2177e911f249SSebastian Wiedenroth
2178e911f249SSebastian Wiedenroth}
2179e911f249SSebastian Wiedenroth
2180e911f249SSebastian Wiedenroth#############################################################################
2181e911f249SSebastian Wiedenroth#
2182e911f249SSebastian Wiedenroth#         logadm23 - test for keeping timestamps in timestamps file on -r
2183e911f249SSebastian Wiedenroth#
2184e911f249SSebastian Wiedenroth#############################################################################
2185e911f249SSebastian Wiedenroth
2186e911f249SSebastian Wiedenrothsub logadm23 {
2187e911f249SSebastian Wiedenroth	set_file('logadm.conf', <<'EOF');
2188e911f249SSebastian Wiedenrothwildcard_test -A 3d dir1/*.log
2189e911f249SSebastian Wiedenrothregular_test -A 3d dir2/test.log
2190e911f249SSebastian WiedenrothEOF
2191e911f249SSebastian Wiedenroth
2192e911f249SSebastian Wiedenrothset_file('logadm.conf.expect', <<'EOF');
2193e911f249SSebastian Wiedenrothwildcard_test -A 3d dir1/*.log
2194e911f249SSebastian WiedenrothEOF
2195e911f249SSebastian Wiedenroth
2196e911f249SSebastian Wiedenroth	set_file('logadm.timestamps', <<'EOF');
2197*bbf21555SRichard Lowe# This file holds internal data for logadm(8).
2198e911f249SSebastian Wiedenroth# Do not edit.
2199e911f249SSebastian Wiedenrothdir1/foo.log -P 'Thu Nov  1 16:56:42 2001'
2200e911f249SSebastian Wiedenrothdir2/test.log -P 'Thu Nov  1 16:56:42 2001'
2201e911f249SSebastian WiedenrothEOF
2202e911f249SSebastian Wiedenroth	system("/bin/cp logadm.timestamps logadm.timestamps.expect");
2203e911f249SSebastian Wiedenroth
2204e911f249SSebastian Wiedenroth	set_file('checktest', <<'EOF');
2205e911f249SSebastian Wiedenroth[ -s std.err ] && { cat std.err; exit 1; }
2206e911f249SSebastian Wiedenroth/bin/diff logadm.conf.expect logadm.conf || exit 1
2207e911f249SSebastian Wiedenroth/bin/diff logadm.timestamps.expect logadm.timestamps || exit 1
2208e911f249SSebastian WiedenrothEOF
2209e911f249SSebastian Wiedenroth
2210e911f249SSebastian Wiedenroth	set_file('runtest', <<"EOF");
2211e911f249SSebastian Wiedenroth# test "logadm23"
2212e911f249SSebastian Wiedenroth$envsetup
2213e911f249SSebastian Wiedenroth$bindir/logadm -f logadm.conf -F logadm.timestamps -r regular_test 2>std.err
2214e911f249SSebastian Wiedenrothexit 0
2215e911f249SSebastian WiedenrothEOF
2216e911f249SSebastian Wiedenroth
2217e911f249SSebastian Wiedenroth}
2218d5dace52SMike Gerdts
2219d5dace52SMike Gerdts###########################################################################
2220d5dace52SMike Gerdts#
2221d5dace52SMike Gerdts#	stderr1 -- ensure verbose stderr does not deadlock
2222d5dace52SMike Gerdts#
2223d5dace52SMike Gerdts###########################################################################
2224d5dace52SMike Gerdtssub stderr1 {
2225d5dace52SMike Gerdts	set_file('logfile', 'initially logfile');
2226d5dace52SMike Gerdts
2227d5dace52SMike Gerdts	set_file('std.err.uniq.expect', <<'EOF');
2228d5dace52SMike Gerdts   1 logadm: Warning: command failed: /bin/sh -c exec 1>&2; for i in {1..250000}; do echo pre-command-stuff; done
2229d5dace52SMike Gerdts250000 pre-command-stuff
2230d5dace52SMike Gerdts   1 logadm: Warning: command failed: /bin/sh -c exec 1>&2; for i in {1..250000}; do echo post-command-stuff; done
2231d5dace52SMike Gerdts250000 post-command-stuff
2232d5dace52SMike GerdtsEOF
2233d5dace52SMike Gerdts
2234d5dace52SMike Gerdts	set_file('checktest', <<'EOF');
2235d5dace52SMike Gerdts[ -s std.out ] && exit 1
2236d5dace52SMike Gerdts/bin/diff -u std.err.uniq.expect std.err.uniq || exit 1
2237d5dace52SMike Gerdtsexit 0
2238d5dace52SMike GerdtsEOF
2239d5dace52SMike Gerdts
2240d5dace52SMike Gerdts	# The output redirection below looks wrong, but it is not.  The redirect
2241d5dace52SMike Gerdts	# of stderr before the redirect of stdout causes stderr to be piped to
2242d5dace52SMike Gerdts	# uniq.
2243d5dace52SMike Gerdts	set_file('runtest', <<"EOF");
2244d5dace52SMike Gerdts# test "stderr1"
2245d5dace52SMike Gerdts$envsetup
2246d5dace52SMike Gerdtsexec $bindir/logadm -f /dev/null -p now logfile \\
2247d5dace52SMike Gerdts    -b 'exec 1>&2; for i in {1..250000}; do echo pre-command-stuff; done' \\
2248d5dace52SMike Gerdts    -a 'exec 1>&2; for i in {1..250000}; do echo post-command-stuff; done' \\
2249d5dace52SMike Gerdts    2>&1 >std.out | uniq -c >std.err.uniq
2250d5dace52SMike GerdtsEOF
2251d5dace52SMike Gerdts}
2252