1f08c3bdfSopenharmony_ci#!/bin/sh
2f08c3bdfSopenharmony_ci################################################################################
3f08c3bdfSopenharmony_ci##                                                                            ##
4f08c3bdfSopenharmony_ci## Copyright (c) International Business Machines  Corp., 2001                 ##
5f08c3bdfSopenharmony_ci##                                                                            ##
6f08c3bdfSopenharmony_ci## This program is free software;  you can redistribute it and#or modify      ##
7f08c3bdfSopenharmony_ci## it under the terms of the GNU General Public License as published by       ##
8f08c3bdfSopenharmony_ci## the Free Software Foundation; either version 2 of the License, or          ##
9f08c3bdfSopenharmony_ci## (at your option) any later version.                                        ##
10f08c3bdfSopenharmony_ci##                                                                            ##
11f08c3bdfSopenharmony_ci## This program is distributed in the hope that it will be useful, but        ##
12f08c3bdfSopenharmony_ci## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
13f08c3bdfSopenharmony_ci## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
14f08c3bdfSopenharmony_ci## for more details.                                                          ##
15f08c3bdfSopenharmony_ci##                                                                            ##
16f08c3bdfSopenharmony_ci## You should have received a copy of the GNU General Public License          ##
17f08c3bdfSopenharmony_ci## along with this program;  if not, write to the Free Software               ##
18f08c3bdfSopenharmony_ci## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
19f08c3bdfSopenharmony_ci##                                                                            ##
20f08c3bdfSopenharmony_ci################################################################################
21f08c3bdfSopenharmony_ci#
22f08c3bdfSopenharmony_ci# File :        logrotate_tests.sh
23f08c3bdfSopenharmony_ci#
24f08c3bdfSopenharmony_ci# Description:    Test Basic functionality of logrotate command.
25f08c3bdfSopenharmony_ci#                Test #1: Test that logrotate -f <file.conf> rotates the logfile
26f08c3bdfSopenharmony_ci#                as per the specifications in the conf file. Create a file
27f08c3bdfSopenharmony_ci#                tst_logfile in /var/log/. Create a conf file such that this
28f08c3bdfSopenharmony_ci#                logfile is set for rotation every week. Execute the command
29f08c3bdfSopenharmony_ci#                logrotate -f <file.conf>, check to see if it forced rotation.
30f08c3bdfSopenharmony_ci#                Test #2: Check if logrotate running as a cronjob will rotate a
31f08c3bdfSopenharmony_ci#                logfile when it exceeds a specific size. Create two cronjobs
32f08c3bdfSopenharmony_ci#                1. runs a command to log a string to a logfile. 2. runs
33f08c3bdfSopenharmony_ci#                logrotate <file.conf> every minute. The conf file specifies
34f08c3bdfSopenharmony_ci#                that the rotation happen only if the log file exceeds 2k file
35f08c3bdfSopenharmony_ci#                size.
36f08c3bdfSopenharmony_ci#
37f08c3bdfSopenharmony_ci# Author:        Manoj Iyer, manjo@mail.utexas.edu
38f08c3bdfSopenharmony_ci#
39f08c3bdfSopenharmony_ci# History:       Dec 23 2002 - Created - Manoj Iyer.
40f08c3bdfSopenharmony_ci#                Dec 24 2002 - Added   - Test #2 - Test to run logrotate as a
41f08c3bdfSopenharmony_ci#                                        cron job.
42f08c3bdfSopenharmony_ci#                Feb 28 2003 - Fixed   - Modified testcase to use functions.
43f08c3bdfSopenharmony_ci#
44f08c3bdfSopenharmony_ci# Function: 	chk_ifexists
45f08c3bdfSopenharmony_ci#
46f08c3bdfSopenharmony_ci# Description:  - Check if command required for this test exits.
47f08c3bdfSopenharmony_ci#
48f08c3bdfSopenharmony_ci# Input:        - $1 - calling test case.
49f08c3bdfSopenharmony_ci#               - $2 - command that needs to be checked.
50f08c3bdfSopenharmony_ci#
51f08c3bdfSopenharmony_ci# Return:		- zero on success.
52f08c3bdfSopenharmony_ci# 				- non-zero on failure.
53f08c3bdfSopenharmony_cichk_ifexists()
54f08c3bdfSopenharmony_ci{
55f08c3bdfSopenharmony_ci	RC=0
56f08c3bdfSopenharmony_ci
57f08c3bdfSopenharmony_ci	which $2 > $LTPTMP/tst_logrotate.err 2>&1 || RC=$?
58f08c3bdfSopenharmony_ci	if [ $RC -ne 0 ]
59f08c3bdfSopenharmony_ci	then
60f08c3bdfSopenharmony_ci		tst_brkm TBROK NULL "$1: command $2 not found."
61f08c3bdfSopenharmony_ci	fi
62f08c3bdfSopenharmony_ci	return $RC
63f08c3bdfSopenharmony_ci}
64f08c3bdfSopenharmony_ci
65f08c3bdfSopenharmony_ci
66f08c3bdfSopenharmony_ci# Function: init
67f08c3bdfSopenharmony_ci#
68f08c3bdfSopenharmony_ci# Description:  - Check if command required for this test exits.
69f08c3bdfSopenharmony_ci#               - Create temporary directories required for this test.
70f08c3bdfSopenharmony_ci#               - Initialize global variables.
71f08c3bdfSopenharmony_ci#
72f08c3bdfSopenharmony_ci# Return:		- zero on success.
73f08c3bdfSopenharmony_ci# 				- non-zero on failure.
74f08c3bdfSopenharmony_ciinit()
75f08c3bdfSopenharmony_ci{
76f08c3bdfSopenharmony_ci	# Initialize global variables.
77f08c3bdfSopenharmony_ci	export RC=0
78f08c3bdfSopenharmony_ci	export TST_TOTAL=2
79f08c3bdfSopenharmony_ci	export TCID="logrotate"
80f08c3bdfSopenharmony_ci	export TST_COUNT=0
81f08c3bdfSopenharmony_ci
82f08c3bdfSopenharmony_ci	# Inititalize cleanup function.
83f08c3bdfSopenharmony_ci	trap "cleanup" 0
84f08c3bdfSopenharmony_ci
85f08c3bdfSopenharmony_ci	# create the temporary directory used by this testcase
86f08c3bdfSopenharmony_ci	if [ -z $TMP ]
87f08c3bdfSopenharmony_ci	then
88f08c3bdfSopenharmony_ci		LTPTMP=/tmp/tst_logrotate.$$
89f08c3bdfSopenharmony_ci	else
90f08c3bdfSopenharmony_ci		LTPTMP=$TMP/tst_logrotate.$$
91f08c3bdfSopenharmony_ci	fi
92f08c3bdfSopenharmony_ci
93f08c3bdfSopenharmony_ci	mkdir -p $LTPTMP > /dev/null 2>&1 || RC=$?
94f08c3bdfSopenharmony_ci	if [ $RC -ne 0 ]
95f08c3bdfSopenharmony_ci	then
96f08c3bdfSopenharmony_ci		 tst_brkm TBROK "INIT: Unable to create temporary directory"
97f08c3bdfSopenharmony_ci		 return $RC
98f08c3bdfSopenharmony_ci	fi
99f08c3bdfSopenharmony_ci
100f08c3bdfSopenharmony_ci	# check if commands tst_*, logrotate, awk and file exists.
101f08c3bdfSopenharmony_ci	chk_ifexists INIT tst_resm  || return $RC
102f08c3bdfSopenharmony_ci	chk_ifexists INIT logrotate || return $RC
103f08c3bdfSopenharmony_ci	chk_ifexists INIT awk       || return $RC
104f08c3bdfSopenharmony_ci	chk_ifexists INIT file      || return $RC
105f08c3bdfSopenharmony_ci
106f08c3bdfSopenharmony_ci	return $RC
107f08c3bdfSopenharmony_ci}
108f08c3bdfSopenharmony_ci
109f08c3bdfSopenharmony_ci
110f08c3bdfSopenharmony_ci# Function: 	cleanup
111f08c3bdfSopenharmony_ci#
112f08c3bdfSopenharmony_ci# Description:  - remove temporaty files and directories. Stop all jobs stated
113f08c3bdfSopenharmony_ci#                 by this testcase.
114f08c3bdfSopenharmony_ci#
115f08c3bdfSopenharmony_ci# Return:		- zero on success.
116f08c3bdfSopenharmony_ci# 				- non-zero on failure.
117f08c3bdfSopenharmony_cicleanup()
118f08c3bdfSopenharmony_ci{
119f08c3bdfSopenharmony_ci	#remove all cronjobs that were installed.
120f08c3bdfSopenharmony_ci	tst_resm TINFO "CLEAN: removing all cron jobs."
121f08c3bdfSopenharmony_ci	crontab -r > /dev/null 2>&1
122f08c3bdfSopenharmony_ci
123f08c3bdfSopenharmony_ci	# remove all the temporary files created by this test.
124f08c3bdfSopenharmony_ci	tst_resm TINFO "CLEAN: removing $LTPTMP"
125f08c3bdfSopenharmony_ci	rm -fr $LTPTMP
126f08c3bdfSopenharmony_ci}
127f08c3bdfSopenharmony_ci
128f08c3bdfSopenharmony_ci
129f08c3bdfSopenharmony_ci# Function: 	test01
130f08c3bdfSopenharmony_ci#
131f08c3bdfSopenharmony_ci# Description:  - Test that logrotate logrotate will rotate the logfile
132f08c3bdfSopenharmony_ci#                 according to the specifications in the config file.
133f08c3bdfSopenharmony_ci#               - create a config file that will rotate the /var/log/tst_logfile
134f08c3bdfSopenharmony_ci#                 file.
135f08c3bdfSopenharmony_ci#               - use force option to force logrotate to cause the log file to
136f08c3bdfSopenharmony_ci#                 be rotated.
137f08c3bdfSopenharmony_ci#               - compress the file after rotation.
138f08c3bdfSopenharmony_ci#
139f08c3bdfSopenharmony_ci# Return:		- zero on success.
140f08c3bdfSopenharmony_ci# 				- non-zero on failure.
141f08c3bdfSopenharmony_citest01()
142f08c3bdfSopenharmony_ci{
143f08c3bdfSopenharmony_ci	count=0
144f08c3bdfSopenharmony_ci	files=" "
145f08c3bdfSopenharmony_ci	filesize=0
146f08c3bdfSopenharmony_ci
147f08c3bdfSopenharmony_ci	TCID=logrotate01
148f08c3bdfSopenharmony_ci	TST_COUNT=1
149f08c3bdfSopenharmony_ci
150f08c3bdfSopenharmony_ci	tst_resm TINFO "Test #1: create a configfile $LTPTMP/var_mesg.config"
151f08c3bdfSopenharmony_ci	tst_resm TINFO "Test #1: use logrotate -f <config> to force rotation"
152f08c3bdfSopenharmony_ci	tst_resm TINFO "Test #1: this will rotate the log file according to"
153f08c3bdfSopenharmony_ci	tst_resm TINFO "Test #1: the specification in the configfile."
154f08c3bdfSopenharmony_ci	tst_resm TINFO "Test #1: 1. rotate /var/log/tst_logfile file."
155f08c3bdfSopenharmony_ci	tst_resm TINFO "Test #1: 2. compresses it."
156f08c3bdfSopenharmony_ci
157f08c3bdfSopenharmony_ci	# Check if syslog group exists
158f08c3bdfSopenharmony_ci	local group="syslog"
159f08c3bdfSopenharmony_ci	grep -q $group /etc/group || group="root"
160f08c3bdfSopenharmony_ci
161f08c3bdfSopenharmony_ci	# create config file.
162f08c3bdfSopenharmony_ci	cat >$LTPTMP/tst_logrotate.conf <<-EOF
163f08c3bdfSopenharmony_ci	#****** Begin Config file *******
164f08c3bdfSopenharmony_ci	# create new (empty) log files after rotating old ones
165f08c3bdfSopenharmony_ci	create
166f08c3bdfSopenharmony_ci
167f08c3bdfSopenharmony_ci	# compress the log files
168f08c3bdfSopenharmony_ci	compress
169f08c3bdfSopenharmony_ci
170f08c3bdfSopenharmony_ci	/var/log/tst_logfile {
171f08c3bdfSopenharmony_ci		su root $group
172f08c3bdfSopenharmony_ci		rotate 5
173f08c3bdfSopenharmony_ci		weekly
174f08c3bdfSopenharmony_ci	}
175f08c3bdfSopenharmony_ci	#****** End Config file *******
176f08c3bdfSopenharmony_ci	EOF
177f08c3bdfSopenharmony_ci
178f08c3bdfSopenharmony_ci	# create a log file in /var/log/
179f08c3bdfSopenharmony_ci	cat >/var/log/tst_logfile <<-EOF
180f08c3bdfSopenharmony_ci	#****** Begin Log File ********
181f08c3bdfSopenharmony_ci	# This is a dummy log file.
182f08c3bdfSopenharmony_ci	#****** End Log File ********
183f08c3bdfSopenharmony_ci	EOF
184f08c3bdfSopenharmony_ci
185f08c3bdfSopenharmony_ci	while [ $count -lt 10 ]
186f08c3bdfSopenharmony_ci	do
187f08c3bdfSopenharmony_ci		echo "This a dummy log file used to test logrotate command." >> \
188f08c3bdfSopenharmony_ci			/var/log/tst_logfile
189f08c3bdfSopenharmony_ci		 		 count=$(( $count+1 ))
190f08c3bdfSopenharmony_ci	done
191f08c3bdfSopenharmony_ci
192f08c3bdfSopenharmony_ci	# remove all old-n-stale logfiles.
193f08c3bdfSopenharmony_ci	for files in /var/log/tst_logfile.*
194f08c3bdfSopenharmony_ci	do
195f08c3bdfSopenharmony_ci		rm -f $files > /dev/null 2>&1
196f08c3bdfSopenharmony_ci	done
197f08c3bdfSopenharmony_ci
198f08c3bdfSopenharmony_ci	chmod 644 $LTPTMP/tst_logrotate.conf
199f08c3bdfSopenharmony_ci	logrotate -fv $LTPTMP/tst_logrotate.conf > $LTPTMP/tst_logrotate.out 2>&1 \
200f08c3bdfSopenharmony_ci		|| RC=$?
201f08c3bdfSopenharmony_ci	if [ $RC -eq 0 ]
202f08c3bdfSopenharmony_ci	then
203f08c3bdfSopenharmony_ci		# check if config file $LTPTMP/tst_logrotate.conf is read
204f08c3bdfSopenharmony_ci		# check if  /etc/logrotate.d is included/
205f08c3bdfSopenharmony_ci		# check if 5 rotations are forced.
206f08c3bdfSopenharmony_ci        # check if compression is done.
207f08c3bdfSopenharmony_ci		grep "reading config file $LTPTMP/tst_logrotate.conf" \
208f08c3bdfSopenharmony_ci			$LTPTMP/tst_logrotate.out   > $LTPTMP/tst_logrotate.err 2>&1 || RC=$?
209f08c3bdfSopenharmony_ci		grep "forced from command line (5 rotations)" \
210f08c3bdfSopenharmony_ci			$LTPTMP/tst_logrotate.out   > $LTPTMP/tst_logrotate.err 2>&1 || RC=$?
211f08c3bdfSopenharmony_ci		egrep "compressing new|log with" \
212f08c3bdfSopenharmony_ci			$LTPTMP/tst_logrotate.out   > $LTPTMP/tst_logrotate.err 2>&1 || RC=$?
213f08c3bdfSopenharmony_ci		if [ $RC -ne 0 ]
214f08c3bdfSopenharmony_ci		then
215f08c3bdfSopenharmony_ci			tst_res TFAIL $LTPTMP/tst_logrotate.err \
216f08c3bdfSopenharmony_ci				"Test #1: logrotate command failed. Reason:"
217f08c3bdfSopenharmony_ci		else
218f08c3bdfSopenharmony_ci			# Check if compressed log file is created.
219f08c3bdfSopenharmony_ci			if [ -f /var/log/tst_logfile.1.gz ]
220f08c3bdfSopenharmony_ci			then
221f08c3bdfSopenharmony_ci				file /var/log/tst_logfile.1.gz | grep "gzip compressed data" \
222f08c3bdfSopenharmony_ci					> $LTPTMP/tst_logrotate.out 2>&1 || RC=$?
223f08c3bdfSopenharmony_ci				if [ $RC -eq 0 ]
224f08c3bdfSopenharmony_ci				then
225f08c3bdfSopenharmony_ci					tst_resm TPASS \
226f08c3bdfSopenharmony_ci						"Test #1: logrotate created a compressed file."
227f08c3bdfSopenharmony_ci				else
228f08c3bdfSopenharmony_ci					tst_res TFAIL $LTPTMP/tst_logrotate.out \
229f08c3bdfSopenharmony_ci						"Test #1: Failed to create a compressed file. Reason:"
230f08c3bdfSopenharmony_ci				fi
231f08c3bdfSopenharmony_ci				return $RC
232f08c3bdfSopenharmony_ci			else
233f08c3bdfSopenharmony_ci				 tst_res TFAIL  $LTPTMP/tst_logrotate.out \
234f08c3bdfSopenharmony_ci				  "Test #1: Failed create /var/log/tst_logfile.1.gz. Reason:"
235f08c3bdfSopenharmony_ci				return $RC
236f08c3bdfSopenharmony_ci			fi
237f08c3bdfSopenharmony_ci		fi
238f08c3bdfSopenharmony_ci	else
239f08c3bdfSopenharmony_ci		tst_res TFAIL $LTPTMP/tst_logrotate.out \
240f08c3bdfSopenharmony_ci		"Test #1: logrotate command exited with $RC return code. Output:"
241f08c3bdfSopenharmony_ci	fi
242f08c3bdfSopenharmony_ci	return $RC
243f08c3bdfSopenharmony_ci}
244f08c3bdfSopenharmony_ci
245f08c3bdfSopenharmony_ci
246f08c3bdfSopenharmony_citest02()
247f08c3bdfSopenharmony_ci{
248f08c3bdfSopenharmony_ci# Test #2
249f08c3bdfSopenharmony_ci# Test that logrotate logrotate will rotate the logfile if the logfile
250f08c3bdfSopenharmony_ci# exceeds a certain size.
251f08c3bdfSopenharmony_ci#     - create a config file that will rotate the /var/log/tst_largelogfile.
252f08c3bdfSopenharmony_ci#     - run logrotate in a cron job that runs every minute.
253f08c3bdfSopenharmony_ci#     - add messages to the logfile until it gets rotated when a re-dittermined
254f08c3bdfSopenharmony_ci#        size is reached.
255f08c3bdfSopenharmony_ci
256f08c3bdfSopenharmony_ciexport TCID=logrotate02
257f08c3bdfSopenharmony_ciexport TST_COUNT=2
258f08c3bdfSopenharmony_ciRC=0
259f08c3bdfSopenharmony_ci
260f08c3bdfSopenharmony_citst_resm TINFO "Test #2: create a configfile $LTPTMP/tst_largelog.conf"
261f08c3bdfSopenharmony_citst_resm TINFO "Test #2: logrotate $LTPTMP/tst_largelog.conf - cronjob"
262f08c3bdfSopenharmony_citst_resm TINFO "Test #2: set to rotate tst_largelogfile when size > 2K"
263f08c3bdfSopenharmony_ci
264f08c3bdfSopenharmony_ci
265f08c3bdfSopenharmony_ci# create config file.
266f08c3bdfSopenharmony_cicat >$LTPTMP/tst_largelog.conf <<EOF
267f08c3bdfSopenharmony_ci# create new (empty) log files after rotating old ones
268f08c3bdfSopenharmony_cicreate
269f08c3bdfSopenharmony_ci
270f08c3bdfSopenharmony_ci# compress the log files
271f08c3bdfSopenharmony_cicompress
272f08c3bdfSopenharmony_ci
273f08c3bdfSopenharmony_ci# RPM packages drop log rotation information into this directory
274f08c3bdfSopenharmony_ciinclude /etc/logrotate.d
275f08c3bdfSopenharmony_ci
276f08c3bdfSopenharmony_ci/var/log/tst_largelogfile {
277f08c3bdfSopenharmony_ci    rotate 5
278f08c3bdfSopenharmony_ci    size=2k
279f08c3bdfSopenharmony_ci}
280f08c3bdfSopenharmony_ciEOF
281f08c3bdfSopenharmony_ci
282f08c3bdfSopenharmony_ci# create the pseudo-log file.
283f08c3bdfSopenharmony_cicat >/var/log/tst_largelogfile <<EOF
284f08c3bdfSopenharmony_ci# This is a psuedo-log file. This file will grow to a 2k size before
285f08c3bdfSopenharmony_ci# getting rotated.
286f08c3bdfSopenharmony_ciEOF
287f08c3bdfSopenharmony_ci
288f08c3bdfSopenharmony_ci# create logrotate cron job.
289f08c3bdfSopenharmony_cicat >$LTPTMP/tst_logrotate.cron <<EOF
290f08c3bdfSopenharmony_ci* * * * * logrotate $LTPTMP/tst_largelog.conf
291f08c3bdfSopenharmony_ciEOF
292f08c3bdfSopenharmony_ci
293f08c3bdfSopenharmony_cichmod 777 $LTPTMP/tst_logrotate.cron > /dev/null 2>&1
294f08c3bdfSopenharmony_ci
295f08c3bdfSopenharmony_citst_resm TINFO "Test #2: Installing cron job to run logrotate"
296f08c3bdfSopenharmony_cicrontab $LTPTMP/tst_logrotate.cron > $LTPTMP/tst_logrotate.out 2>&1 || RC=$?
297f08c3bdfSopenharmony_ciif [ $RC -ne 0 ]
298f08c3bdfSopenharmony_cithen
299f08c3bdfSopenharmony_ci    echo "Exit status of crontab command: $RC" >> tst_logrotate.out 2>/dev/null
300f08c3bdfSopenharmony_ci    tst_brk TBROK $LTPTMP/tst_logrotate.out NULL \
301f08c3bdfSopenharmony_ci        "Test #2: crontab Broke while installing cronjob. Reason:"
302f08c3bdfSopenharmony_ci    TFAILCNT=$(( $TFAILCN+1 ))
303f08c3bdfSopenharmony_cielse
304f08c3bdfSopenharmony_ci    tst_resm TINFO "Test #2: Cronjob installed successfully"
305f08c3bdfSopenharmony_cifi
306f08c3bdfSopenharmony_ci
307f08c3bdfSopenharmony_ci# cron job to increase the log file size.
308f08c3bdfSopenharmony_cicat >$LTPTMP/tst_addtolog.cron <<EOF
309f08c3bdfSopenharmony_ci
310f08c3bdfSopenharmony_ci* * * * * echo "To Err Is Human, To Really Screw Up You Need A Computer."  >>/var/log/tst_largelogfile 2>/dev/null
311f08c3bdfSopenharmony_ciEOF
312f08c3bdfSopenharmony_ci
313f08c3bdfSopenharmony_citst_resm TINFO "Test #2: Installing cron job to increase logsize"
314f08c3bdfSopenharmony_cicrontab $LTPTMP/tst_addtolog.cron > $LTPTMP/tst_logrotate.out 2>&1 || RC=$?
315f08c3bdfSopenharmony_ciif [ $RC -ne 0 ]
316f08c3bdfSopenharmony_cithen
317f08c3bdfSopenharmony_ci    echo "Exit status of crontab command: $RC" >> tst_logrotate.out 2>/dev/null
318f08c3bdfSopenharmony_ci    tst_brk TBROK $LTPTMP/tst_logrotate.out NULL \
319f08c3bdfSopenharmony_ci        "Test #2: crontab Broke while installing cronjob. Reason:"
320f08c3bdfSopenharmony_ci    TFAILCNT=$(( $TFAILCN+1 ))
321f08c3bdfSopenharmony_cielse
322f08c3bdfSopenharmony_ci    tst_resm TINFO "Test #2: Cronjob installed successfully"
323f08c3bdfSopenharmony_cifi
324f08c3bdfSopenharmony_ci
325f08c3bdfSopenharmony_ci# let cron jobs get started.
326f08c3bdfSopenharmony_cisleep 10s
327f08c3bdfSopenharmony_ci
328f08c3bdfSopenharmony_ci# increase the log file size.
329f08c3bdfSopenharmony_ci
330f08c3bdfSopenharmony_ci# wait for the /var/log/tst_largelogfile to be filled to a size greater than 2k
331f08c3bdfSopenharmony_citst_resm TINFO "Test #2: Checking if file size is > 2k"
332f08c3bdfSopenharmony_citst_resm TINFO "Test #2: Pls be patient this will take some time."
333f08c3bdfSopenharmony_citst_resm TINFO "Test #2: or killall -9 logrotate02 to skip.."
334f08c3bdfSopenharmony_ciif [ -f `which awk` ]
335f08c3bdfSopenharmony_cithen
336f08c3bdfSopenharmony_ci    while [ $filesize -lt 2046 ]
337f08c3bdfSopenharmony_ci    do
338f08c3bdfSopenharmony_ci        filesize=`ls -l /var/log/tst_largelogfile | awk '{print $5}'`
339f08c3bdfSopenharmony_ci    done
340f08c3bdfSopenharmony_ci	# wait for 1m  and check if logrotate has rotated the logfile. The cron job
341f08c3bdfSopenharmony_ci	# that does a logrotate runs every 1 minute so give the cron a minute...
342f08c3bdfSopenharmony_ci	sleep 1m
343f08c3bdfSopenharmony_cielse
344f08c3bdfSopenharmony_ci	tst_resm TINFO "Test #2: No AWK installed ... sleeping for 10mts"
345f08c3bdfSopenharmony_ci	sleep 10m
346f08c3bdfSopenharmony_cifi
347f08c3bdfSopenharmony_ci
348f08c3bdfSopenharmony_ci
349f08c3bdfSopenharmony_ciif [ -f /var/log/tst_largelogfile.1.gz ]
350f08c3bdfSopenharmony_cithen
351f08c3bdfSopenharmony_ci    file /var/log/tst_largelogfile.1.gz | grep "gzip compressed data" \
352f08c3bdfSopenharmony_ci        > $LTPTMP/tst_logrotate.out 2>&1 || RC=$?
353f08c3bdfSopenharmony_ci    if [ $RC -eq 0 ]
354f08c3bdfSopenharmony_ci    then
355f08c3bdfSopenharmony_ci        tst_resm TPASS \
356f08c3bdfSopenharmony_ci            "Test #1: logrotate worked as cron, created a compressed file."
357f08c3bdfSopenharmony_ci    else
358f08c3bdfSopenharmony_ci        tst_res TFAIL $LTPTMP/tst_logrotate.out \
359f08c3bdfSopenharmony_ci            "Test #1: Failed to create a compressed file. Reason:"
360f08c3bdfSopenharmony_ci    fi
361f08c3bdfSopenharmony_cielse
362f08c3bdfSopenharmony_ci    tst_res TFAIL  $LTPTMP/tst_logrotate.out \
363f08c3bdfSopenharmony_ci        "Test #1: Failed to create /var/log/tst_largelogfile.1.gz. Reason:"
364f08c3bdfSopenharmony_ci    TFAILCNT=$(( $TFAILCNT+1 ))
365f08c3bdfSopenharmony_cifi
366f08c3bdfSopenharmony_ci
367f08c3bdfSopenharmony_ci}
368f08c3bdfSopenharmony_ci
369f08c3bdfSopenharmony_ci# Function:	main
370f08c3bdfSopenharmony_ci#
371f08c3bdfSopenharmony_ci# Description:	- Execute all tests and report results.
372f08c3bdfSopenharmony_ci#
373f08c3bdfSopenharmony_ci# Exit:			- zero on success
374f08c3bdfSopenharmony_ci#               - non-zero on failure.
375f08c3bdfSopenharmony_ci
376f08c3bdfSopenharmony_ciRC=0
377f08c3bdfSopenharmony_ciinit || exit $?
378f08c3bdfSopenharmony_ci
379f08c3bdfSopenharmony_citest01 || RC=$?
380f08c3bdfSopenharmony_ci
381f08c3bdfSopenharmony_ciexit $RC
382