File: logrotate.test

package info (click to toggle)
yasat 848-1
  • links: PTS
  • area: main
  • in suites: buster, stretch
  • size: 1,052 kB
  • ctags: 9
  • sloc: sh: 6,127; makefile: 47
file content (68 lines) | stat: -rw-r--r-- 2,630 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/sh
################################################################################
#                                                                              #
#   Copyright (C) 2008-2015 LABBE Corentin <clabbe.montjoie@gmail.com>
#
#    YASAT is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    YASAT is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with YASAT.  If not, see <http://www.gnu.org/licenses/>.
#                                                                              #
################################################################################

#TODO FreeBSD dont use logrotate

Title "Check logrotate configurations"

#YASAT_TEST_LOGROTATE CCEID=4182-2 NSAG=2.6.1.3.1 Check if all logs is rotated
if [ ! -e /etc/logrotate.conf ] ;then
	Display --indent 2 --text "No logrotate" --result NOTFOUND --color RED
	return 1;
fi

#solaris have logs in others directory

find /var/log/ -type f | grep 'log$' | grep -v Xorg. |grep -v 'faillog$'|grep -v 'lastlog$' |
while read line
do
	RESULT=`grep -ri $line /etc/logrotate.*`
	if [ -z "${RESULT}" ]
	then
#		echo "XXXX=========================================================="
		#Test wildcards
		DEFINED_IN_WILD=0
		LOGROTATE_WILDS="`grep -ri '/var/log/' /etc/logrotate.* | grep '*' | sed 's/[[:space:]]{.*//g'`"
		for wilds in $LOGROTATE_WILDS
		do
			LOGROTATE_WILDS_DEFINE="`echo $wilds | cut -d\: -f1`"
			LOGROTATE_WILDS_LOGS=`echo $wilds | cut -d\: -f2`
#			echo "$LOGROTATE_WILDS_DEFINE $LOGROTATE_WILDS_LOGS"
			LOGROTATE_WILDS_ALLLOG=`echo $LOGROTATE_WILDS_LOGS`
			for wild in `echo $LOGROTATE_WILDS_ALLLOG`
			do
				if [ ! -z "`echo $line | grep $wild`" ]
				then
					Display --indent 2 --text "$line by `echo $LOGROTATE_WILDS_DEFINE | cut -d\: -f1`" --result FOUND --color GREEN
					DEFINED_IN_WILD=1
				fi
			done
		done
#		echo "=========================================================="
		if [ $DEFINED_IN_WILD -eq 0 ] ;then
			Display --indent 2 --text "$line is not rotated" --result NOTFOUND --color RED --advice LOGROTATE_NOT_ROTATED
		fi
	else
		Display --indent 2 --text "$line by `echo $RESULT | cut -d\: -f1`" --result FOUND --color GREEN
	fi


done