]> granicus.if.org Git - sysstat/blob - sa2.in
Start version 10.0.0.
[sysstat] / sa2.in
1 #!/bin/sh
2 # @SA_LIB_DIR@/sa2
3 # (C) 1999-2011 Sebastien Godard (sysstat <at> orange.fr)
4 #
5 #@(#) @PACKAGE_NAME@-@PACKAGE_VERSION@
6 #@(#) sa2: Write a daily report
7 #
8 S_TIME_FORMAT=ISO ; export S_TIME_FORMAT
9 umask 0022
10 prefix=@prefix@
11 exec_prefix=@exec_prefix@
12 # Add a trailing slash so that 'find' can go through this directory if it's a symlink
13 DDIR=@SA_DIR@/
14 SYSCONFIG_DIR=@SYSCONFIG_DIR@
15 YESTERDAY=@YESTERDAY@
16 DATE=`date ${YESTERDAY} +%d`
17 CURRENTFILE=sa${DATE}
18 CURRENTRPT=sar${DATE}
19 HISTORY=@HISTORY@
20 COMPRESSAFTER=@COMPRESSAFTER@
21 ZIP="@ZIP@"
22 [ -r ${SYSCONFIG_DIR}/sysstat ] && . ${SYSCONFIG_DIR}/sysstat
23 if [ ${HISTORY} -gt 28 ]
24 then
25         CURRENTDIR=`date ${YESTERDAY} +%Y%m`
26         cd ${DDIR} || exit 1
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
40         rm -f ${CURRENTRPT}
41         ln -s ${CURRENTDIR}/${CURRENTRPT} ${CURRENTRPT}
42         CURRENTDIR=${DDIR}/${CURRENTDIR}
43 else
44         CURRENTDIR=${DDIR}
45 fi
46 RPT=${CURRENTDIR}/${CURRENTRPT}
47 ENDIR=@bindir@
48 DFILE=${CURRENTDIR}/${CURRENTFILE}
49 [ -f "$DFILE" ] || exit 0
50 cd ${ENDIR}
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
57 # Remove broken links
58 for f in `find ${DDIR} \( -name 'sar??' -o -name 'sa??' \) -type l`; do
59         [ -e $f ] || rm -f $f
60 done
61 cd ${DDIR}
62 rmdir [0-9]????? > /dev/null 2>&1
63