~ubuntu-branches/ubuntu/warty/sysstat/warty

« back to all changes in this revision

Viewing changes to contrib/sargon/sargon

  • Committer: Bazaar Package Importer
  • Author(s): Robert Luberda
  • Date: 2004-06-15 18:47:50 UTC
  • Revision ID: james.westby@ubuntu.com-20040615184750-y9zskvg3k6tf9j15
Tags: upstream-5.0.5
ImportĀ upstreamĀ versionĀ 5.0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
# Usage: sargon [interval] [count] [days-to-keep] [days-to-keep-uncompressed]
 
4
# Author: John Caruso
 
5
# Modified by Sebastien Godard
 
6
#
 
7
# Synopsis: Replacement for Sun's sar data collection scripts (/usr/lib/sa/sa1
 
8
# and /usr/lib/sa/sa2).  It uses a month-by-month directory structure to allow
 
9
# it to keep more than one month's data; datafiles are named YYMMMM/saDD,
 
10
# and the script maintains links to these datafiles to mimic the standard sar
 
11
# datafile structure.
 
12
#
 
13
# The script does all of what sa1 does and most of what sa2 does, but it
 
14
# doesn't bother doing the sar data summarization that sa2 performs since that
 
15
# data can be generated easily if/when it's needed.
 
16
#
 
17
# Files are automatically compressed or deleted after specified periods.
 
18
#
 
19
# 5/24/2001: Modified to work with Redhat Linux + sysstat 4.0.0
 
20
#
 
21
 
 
22
PATH=/usr/bin:/bin
 
23
 
 
24
# Modified by SG
 
25
INTERVAL=${1:-1}
 
26
COUNT=${2:-1}
 
27
KEEPDAYS=${3:-365}
 
28
COMPRESSAFTER=${4:-180}
 
29
 
 
30
if [ -d /var/adm/sa ]; then
 
31
        SARDATADIR=/var/adm/sa
 
32
elif [ -d /var/log/sa ]; then
 
33
        SARDATADIR=/var/log/sa
 
34
else
 
35
        exit 1
 
36
fi
 
37
CURRENTDIR=`date +%Y%m`
 
38
CURRENTFILE=sa`date +%d`
 
39
FULLCURRENTFILE=$SARDATADIR/$CURRENTDIR/$CURRENTFILE
 
40
 
 
41
SADCDIR=/usr/lib/sa
 
42
SADC=$SADCDIR/sadc
 
43
 
 
44
MAINTTIME=0300
 
45
LASTMAINTFLAG=LASTMAINT
 
46
 
 
47
cd $SARDATADIR || exit 1
 
48
 
 
49
[ -d $CURRENTDIR ] || mkdir -p $CURRENTDIR
 
50
touch $CURRENTDIR/$CURRENTFILE
 
51
 
 
52
# This is all that's left of Sun's original sa1 script.  The cd probably isn't
 
53
# necessary, but who knows, maybe sadc won't work without it.  No harm.
 
54
#
 
55
(cd $SADCDIR; exec $SADC $INTERVAL $COUNT $FULLCURRENTFILE)
 
56
 
 
57
# Remove the "compatibility" link and recreate it to point to the (new)
 
58
# current file (this is done to preserve compatibility with Sun's current
 
59
# sa1/sa2 datafile creation strategy).
 
60
#
 
61
rm -f $CURRENTFILE
 
62
ln -s $CURRENTDIR/$CURRENTFILE $CURRENTFILE
 
63
 
 
64
# We use a special flag file to determine if we need to remove old files--
 
65
# the removal is only done if the flag file is > 1 day old.  This allows the
 
66
# script to be run at any interval and still clean up after itself, but keeps
 
67
# it from cleaning up too often if it's run frequently.
 
68
#
 
69
[ -f $LASTMAINTFLAG ] || touch "`date +%m%d`$MAINTTIME" $LASTMAINTFLAG
 
70
 
 
71
if [ -n "`find $LASTMAINTFLAG -mtime +1 -print`" ]; then
 
72
        find  *  -type f -name "sa??" -o -name "sa??.gz" -mtime +$KEEPDAYS  \
 
73
                -exec rm -f {} \;
 
74
        find  [0-9]????? -name "sa??" -mtime +$COMPRESSAFTER -type f        \
 
75
                         -exec gzip {} \; > /dev/null 2>&1
 
76
        rmdir [0-9]?????  > /dev/null 2>&1
 
77
        rm $LASTMAINTFLAG
 
78
fi
 
79