~ubuntu-branches/ubuntu/gutsy/sysstat/gutsy-backports

« back to all changes in this revision

Viewing changes to sa2.in

  • Committer: Bazaar Package Importer
  • Author(s): Robert Luberda
  • Date: 2007-05-03 11:05:07 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20070503110507-myx4tgq3em3dndbb
Tags: 7.1.4-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/bin/sh
2
 
# SA_LIB_DIR/sa2
 
2
# @SA_LIB_DIR@/sa2
3
3
# (C) 1999-2007 Sebastien Godard (sysstat <at> wanadoo.fr)
4
4
#
5
 
# Changes:
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
10
6
#
11
7
S_TIME_FORMAT=ISO ; export S_TIME_FORMAT
12
8
umask 0022
13
 
DDIR=SA_DIR
14
 
DATE=`date YESTERDAY +%d`
 
9
prefix=@prefix@
 
10
exec_prefix=@exec_prefix@
 
11
# Add a trailing slash so that 'find' can go through this directory if it's a symlink
 
12
DDIR=@SA_DIR@/
 
13
SYSCONFIG_DIR=@SYSCONFIG_DIR@
 
14
YESTERDAY=@YESTERDAY@
 
15
DATE=`date ${YESTERDAY} +%d`
15
16
CURRENTFILE=sa${DATE}
16
17
CURRENTRPT=sar${DATE}
17
 
HISTORY=7
18
 
COMPRESSAFTER=10
19
 
# [ -r /etc/sysconfig/sysstat ] && . /etc/sysconfig/sysstat
20
 
[ -r /etc/sysstat/config ] && . /etc/sysstat/config
 
18
HISTORY=@HISTORY@
 
19
COMPRESSAFTER=@COMPRESSAFTER@
 
20
[ -r ${SYSCONFIG_DIR}/sysstat ] && . ${SYSCONFIG_DIR}/sysstat
21
21
if [ ${HISTORY} -gt 28 ]
22
22
then
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}
26
 
 
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
32
 
                
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} 
37
 
 
38
 
 
 
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
46
42
        CURRENTDIR=${DDIR}
47
43
fi
48
44
RPT=${CURRENTDIR}/${CURRENTRPT}
49
 
ENDIR=BIN_DIR
 
45
ENDIR=@bindir@
50
46
DFILE=${CURRENTDIR}/${CURRENTFILE}
51
47
[ -f "$DFILE" ] || exit 0
52
48
cd ${ENDIR}
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
59
 
# remove broken links   
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
 
55
# Remove broken links
 
56
for f in `find ${DDIR} \( -name 'sar??' -o -name 'sa??' \) -type l`; do
 
57
        [ -e $f ] || rm -f $f
 
58
done
62
59
cd ${DDIR}
63
60
rmdir [0-9]????? > /dev/null 2>&1
64
61
exit 0