]> granicus.if.org Git - sysstat/blob - sa1.in
Prevent sar from appending data to data from the preceding month
[sysstat] / sa1.in
1 #!/bin/sh
2 # @SA_LIB_DIR@/sa1
3 # (C) 1999-2014 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
9 # Set default value for some variables.
10 # Used only if ${SYSCONFIG_DIR}/sysstat doesn't exist!
11 HISTORY=0
12 SADC_OPTIONS=""
13 DDIR=@SA_DIR@
14 DATE=`date +%d`
15 CURRENTFILE=sa${DATE}
16 CURRENTDIR=`date +%Y%m`
17 SYSCONFIG_DIR=@SYSCONFIG_DIR@
18 umask 0022
19
20 [ -r ${SYSCONFIG_DIR}/sysstat ] && . ${SYSCONFIG_DIR}/sysstat
21 if [ ${HISTORY} -gt 25 ]
22 then
23         cd ${DDIR} || exit 1
24         [ -d ${CURRENTDIR} ] || mkdir -p ${CURRENTDIR}
25         # If ${CURRENTFILE} exists and is a regular file, then make sure
26         # the file was modified this day (and not e.g. month ago)
27         # and move it to ${CURRENTDIR}
28         [ ! -L ${CURRENTFILE} ] &&
29                 [ -f ${CURRENTFILE} ] &&
30                 [ "`date +%Y%m%d -r ${CURRENTFILE}`" = "${CURRENTDIR}${DATE}" ] &&
31                 mv -f ${CURRENTFILE} ${CURRENTDIR}/${CURRENTFILE}
32         touch ${CURRENTDIR}/${CURRENTFILE}
33         # Remove the "compatibility" link and recreate it to point to
34         # the (new) current file
35         rm -f ${CURRENTFILE}
36         ln -s ${CURRENTDIR}/${CURRENTFILE} ${CURRENTFILE}
37 else
38         # If ${CURRENTFILE} exists, is a regular file and is from a previous
39         # month then delete it so that it is recreated by sadc afresh
40         [ -f ${CURRENTFILE} ] && [ "`date +%Y%m -r ${CURRENTFILE}`" -lt "${CURRENTDIR}" ] && rm -f ${CURRENTFILE}
41 fi
42
43 ENDIR=@SA_LIB_DIR@
44 cd ${ENDIR}
45 [ "$1" = "--boot" ] && shift && BOOT=y || BOOT=n
46 if [ $# = 0 ] && [ "${BOOT}" = "n" ]
47 then
48 # Note: Stats are written at the end of previous file *and* at the
49 # beginning of the new one (when there is a file rotation) only if
50 # outfile has been specified as '-' on the command line...
51         exec ${ENDIR}/sadc -F -L ${SADC_OPTIONS} 1 1 -
52 else
53         exec ${ENDIR}/sadc -F -L ${SADC_OPTIONS} $* -
54 fi
55