]> granicus.if.org Git - sysstat/blob - sa1.in
sadc now overwrites its daily data file when it is from a previous month.
[sysstat] / sa1.in
1 #!/bin/sh
2 # @SA_LIB_DIR@/sa1
3 # (C) 1999-2011 Sebastien Godard (sysstat <at> orange.fr)
4 #
5 #@(#) @PACKAGE_NAME@-@PACKAGE_VERSION@
6 #@(#) sa1: Collect and store binary data in system activity data file.
7 #
8 HISTORY=0
9 SADC_OPTIONS=""
10 SYSCONFIG_DIR=@SYSCONFIG_DIR@
11 [ -r ${SYSCONFIG_DIR}/sysstat ] && . ${SYSCONFIG_DIR}/sysstat
12 if [ ${HISTORY} -gt 28 ]
13 then
14         CURRENTDIR=`date +%Y%m`
15         DATE=`date +%d`
16         CURRENTFILE=sa${DATE}
17         DDIR=@SA_DIR@
18         cd ${DDIR} || exit 1
19         [ -d ${CURRENTDIR} ] || mkdir -p ${CURRENTDIR}
20         # If ${CURRENTFILE} exists and is a regular file, then make sure
21         # the file was modified this day (and not e.g. month ago)
22         # and move it to ${CURRENTDIR}
23         [ ! -L ${CURRENTFILE} ] &&
24                 [ -f ${CURRENTFILE} ] &&
25                 [ "`date +%Y%m%d -r ${CURRENTFILE}`" = "${CURRENTDIR}${DATE}" ] &&
26                 mv -f ${CURRENTFILE} ${CURRENTDIR}/${CURRENTFILE}
27         touch ${CURRENTDIR}/${CURRENTFILE}
28         # Remove the "compatibility" link and recreate it to point to
29         # the (new) current file
30         rm -f ${CURRENTFILE}
31         ln -s ${CURRENTDIR}/${CURRENTFILE} ${CURRENTFILE}
32 fi
33 umask 0022
34 ENDIR=@SA_LIB_DIR@
35 cd ${ENDIR}
36 [ "$1" = "--boot" ] && shift && BOOT=y || BOOT=n
37 if [ $# = 0 ] && [ "${BOOT}" = "n" ]
38 then
39 # Note: Stats are written at the end of previous file *and* at the
40 # beginning of the new one (when there is a file rotation) only if
41 # outfile has been specified as '-' on the command line...
42         exec ${ENDIR}/sadc -F -L ${SADC_OPTIONS} 1 1 -
43 else
44         exec ${ENDIR}/sadc -F -L ${SADC_OPTIONS} $* -
45 fi
46