forked from sysstat/sysstat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sa2.in
79 lines (66 loc) · 1.58 KB
/
sa2.in
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
69
70
71
72
73
74
75
76
77
78
79
#!/bin/sh
# @SA_LIB_DIR@/sa2
# (C) 1999-2021 Sebastien Godard (sysstat <at> orange.fr)
#
#@(#) @PACKAGE_NAME@-@PACKAGE_VERSION@
#@(#) sa2: Write a daily report
#
S_TIME_FORMAT=ISO ; export S_TIME_FORMAT
prefix=@prefix@
exec_prefix=@exec_prefix@
SA_DIR=@SA_DIR@
SYSCONFIG_DIR=@SYSCONFIG_DIR@
SYSCONFIG_FILE=@SYSCONFIG_FILE@
HISTORY=@HISTORY@
COMPRESSAFTER=@COMPRESSAFTER@
ZIP="@ZIP@"
UMASK=0022
ENDIR=@SAR_DIR@
DELAY_RANGE=@DELAY_RANGE@
# Read configuration file, overriding variables set above
[ -r ${SYSCONFIG_DIR}/${SYSCONFIG_FILE} ] && . ${SYSCONFIG_DIR}/${SYSCONFIG_FILE}
umask ${UMASK}
# Wait for a random delay if requested
if [ ${DELAY_RANGE} -gt 0 ]
then
RANDOM=$$
DELAY=$((${RANDOM}%${DELAY_RANGE}))
sleep ${DELAY}
fi
[ -d ${SA_DIR} ] || SA_DIR=@SA_DIR@
# if YESTERDAY=no then today's summary is generated
if [ x$YESTERDAY = xno ]
then
DATE_OPTS=
else
DATE_OPTS="--date=yesterday"
fi
if [ ${HISTORY} -gt 28 ]
then
DATE=`date ${DATE_OPTS} +%Y%m%d`
else
DATE=`date ${DATE_OPTS} +%d`
fi
CURRENTFILE=sa${DATE}
CURRENTRPT=sar${DATE}
RPT=${SA_DIR}/${CURRENTRPT}
DFILE=${SA_DIR}/${CURRENTFILE}
if [ -z "${ENDIR}" ];
then
ENDIR=@bindir@
fi
[ -f "${DFILE}" ] || exit 0
cd ${ENDIR}
if [ x${REPORTS} != xfalse ]
then
${ENDIR}/sar $* -f ${DFILE} > ${RPT}
fi
SAFILES_REGEX='/sar?[0-9]{2,8}(\.(Z|gz|bz2|xz|lz|lzo))?$'
find "${SA_DIR}" -type f -mtime +${HISTORY} \
| egrep "${SAFILES_REGEX}" \
| xargs rm -f
UNCOMPRESSED_SAFILES_REGEX='/sar?[0-9]{2,8}$'
find "${SA_DIR}" -type f -mtime +${COMPRESSAFTER} \
| egrep "${UNCOMPRESSED_SAFILES_REGEX}" \
| xargs -r "${ZIP}" > /dev/null
exit 0