3
3
# (C) 1999-2007 Sebastien Godard (sysstat <at> wanadoo.fr)
6
# - 2004-01-22 Nils Philippsen <nphilipp@redhat.com>
7
# make history configurable
8
# - 2007-01-21 Sebastien Godard (sysstat <at> wanadoo.fr)
9
# Support for multiple months history.
5
# sa2: Write a daily report
11
7
S_TIME_FORMAT=ISO ; export S_TIME_FORMAT
14
DATE=`date YESTERDAY +%d`
10
exec_prefix=@exec_prefix@
11
# Add a trailing slash so that 'find' can go through this directory if it's a symlink
13
SYSCONFIG_DIR=@SYSCONFIG_DIR@
15
DATE=`date ${YESTERDAY} +%d`
15
16
CURRENTFILE=sa${DATE}
16
17
CURRENTRPT=sar${DATE}
19
# [ -r /etc/sysconfig/sysstat ] && . /etc/sysconfig/sysstat
20
[ -r /etc/sysstat/config ] && . /etc/sysstat/config
19
COMPRESSAFTER=@COMPRESSAFTER@
20
[ -r ${SYSCONFIG_DIR}/sysstat ] && . ${SYSCONFIG_DIR}/sysstat
21
21
if [ ${HISTORY} -gt 28 ]
23
CURRENTDIR=`date YESTERDAY +%Y%m`
23
CURRENTDIR=`date ${YESTERDAY} +%Y%m`
24
24
cd ${DDIR} || exit 1
25
25
[ -d ${CURRENTDIR} ] || mkdir -p ${CURRENTDIR}
27
# Check if CURRENTFILE is the correct file created at $DATE
26
# Check if ${CURRENTFILE} is the correct file created at ${DATE}
28
27
# Note: using `-ge' instead of `=' since the file could have
29
28
# the next day time stamp because of the file rotating feature of sadc
30
29
[ -f ${CURRENTFILE} ] &&
31
30
[ "`date +%Y%m%d -r ${CURRENTFILE}`" -ge "${CURRENTDIR}${DATE}" ] || exit 0
33
# If the file is a regular file, then move it to $CURRENTDIR
34
[ ! -L ${CURRENTFILE} ] &&
31
# If the file is a regular file, then move it to ${CURRENTDIR}
32
[ ! -L ${CURRENTFILE} ] &&
35
33
mv -f ${CURRENTFILE} ${CURRENTDIR}/${CURRENTFILE} &&
36
ln -s ${CURRENTDIR}/${CURRENTFILE} ${CURRENTFILE}
34
ln -s ${CURRENTDIR}/${CURRENTFILE} ${CURRENTFILE}
39
35
touch ${CURRENTDIR}/${CURRENTRPT}
40
36
# Remove the "compatibility" link and recreate it to point to
41
37
# the (new) current file
55
51
find ${DDIR} \( -name 'sar??' -o -name 'sa??' -o -name 'sar??.gz' -o -name 'sa??.gz' \) \
56
52
-mtime +"${HISTORY}" -exec rm -f {} \;
57
53
find ${DDIR} \( -name 'sar??' -o -name 'sa??' \) -type f -mtime +"${COMPRESSAFTER}" \
58
-exec gzip {} \; > /dev/null 2>&1
60
find -L ${DDIR} \( -name 'sar??' -o -name 'sa??' \) -type l \
61
-exec rm -f {} \; > /dev/null 2>&1
54
-exec gzip -9 {} \; > /dev/null 2>&1
56
for f in `find ${DDIR} \( -name 'sar??' -o -name 'sa??' \) -type l`; do
63
60
rmdir [0-9]????? > /dev/null 2>&1