3
# Usage: sargon [interval] [count] [days-to-keep] [days-to-keep-uncompressed]
5
# Modified by Sebastien Godard
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
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.
17
# Files are automatically compressed or deleted after specified periods.
19
# 5/24/2001: Modified to work with Redhat Linux + sysstat 4.0.0
28
COMPRESSAFTER=${4:-180}
30
if [ -d /var/adm/sa ]; then
31
SARDATADIR=/var/adm/sa
32
elif [ -d /var/log/sa ]; then
33
SARDATADIR=/var/log/sa
37
CURRENTDIR=`date +%Y%m`
38
CURRENTFILE=sa`date +%d`
39
FULLCURRENTFILE=$SARDATADIR/$CURRENTDIR/$CURRENTFILE
45
LASTMAINTFLAG=LASTMAINT
47
cd $SARDATADIR || exit 1
49
[ -d $CURRENTDIR ] || mkdir -p $CURRENTDIR
50
touch $CURRENTDIR/$CURRENTFILE
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.
55
(cd $SADCDIR; exec $SADC $INTERVAL $COUNT $FULLCURRENTFILE)
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).
62
ln -s $CURRENTDIR/$CURRENTFILE $CURRENTFILE
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.
69
[ -f $LASTMAINTFLAG ] || touch "`date +%m%d`$MAINTTIME" $LASTMAINTFLAG
71
if [ -n "`find $LASTMAINTFLAG -mtime +1 -print`" ]; then
72
find * -type f -name "sa??" -o -name "sa??.gz" -mtime +$KEEPDAYS \
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