3 # (C) 1999-2014 Sebastien Godard (sysstat <at> orange.fr)
5 #@(#) @PACKAGE_NAME@-@PACKAGE_VERSION@
6 #@(#) sa2: Write a daily report
8 S_TIME_FORMAT=ISO ; export S_TIME_FORMAT
11 exec_prefix=@exec_prefix@
12 # Add a trailing slash so that 'find' can go through this directory if it's a symlink
14 SYSCONFIG_DIR=@SYSCONFIG_DIR@
16 DATE=`date ${YESTERDAY} +%d`
20 COMPRESSAFTER=@COMPRESSAFTER@
22 [ -r ${SYSCONFIG_DIR}/sysstat ] && . ${SYSCONFIG_DIR}/sysstat
23 if [ ${HISTORY} -gt 28 ]
25 CURRENTDIR=`date ${YESTERDAY} +%Y%m`
27 [ -d ${CURRENTDIR} ] || mkdir -p ${CURRENTDIR}
28 # Check if ${CURRENTFILE} is the correct file created at ${DATE}
29 # Note: using `-ge' instead of `=' since the file could have
30 # the next day time stamp because of the file rotating feature of sadc
31 [ -f ${CURRENTFILE} ] &&
32 [ "`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} ] &&
35 mv -f ${CURRENTFILE} ${CURRENTDIR}/${CURRENTFILE} &&
36 ln -s ${CURRENTDIR}/${CURRENTFILE} ${CURRENTFILE}
37 touch ${CURRENTDIR}/${CURRENTRPT}
38 # Remove the "compatibility" link and recreate it to point to
39 # the (new) current file
41 ln -s ${CURRENTDIR}/${CURRENTRPT} ${CURRENTRPT}
42 CURRENTDIR=${DDIR}/${CURRENTDIR}
46 RPT=${CURRENTDIR}/${CURRENTRPT}
48 DFILE=${CURRENTDIR}/${CURRENTFILE}
49 [ -f "$DFILE" ] || exit 0
51 [ -L ${RPT} ] && rm -f ${RPT}
52 ${ENDIR}/sar $* -f ${DFILE} > ${RPT}
53 find ${DDIR} \( -name 'sar??' -o -name 'sa??' -o -name 'sar??.gz' -o -name 'sa??.gz' -o -name 'sar??.bz2' -o -name 'sa??.bz2' \) \
54 -mtime +"${HISTORY}" -exec rm -f {} \;
55 find ${DDIR} \( -name 'sar??' -o -name 'sa??' \) -type f -mtime +"${COMPRESSAFTER}" \
56 -exec ${ZIP} {} \; > /dev/null 2>&1
58 for f in `find ${DDIR} \( -name 'sar??' -o -name 'sa??' \) -type l`; do
62 rmdir [0-9]????? > /dev/null 2>&1