archie/release/B/scripts/daily.admin
2024-05-28 16:48:29 +02:00

203 lines
4.3 KiB
Bash
Executable File

#!/bin/sh
#
# This adminstration file contains commands that archuser should run once a
# day. A good time is somewhere around midnight, local time
#
# 1995 (c) Bunyip Information Systems Inc.
# written by Luc Boulianne <lucb@bunyip.com>
#
# $Id: daily.admin,v 1.4 1995/03/14 21:20:57 pedro Exp $
#
prog=$0
MAIL=/usr/ucb/Mail
PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin
export PATH
usage()
{
cat - <<EOC
Usage: $0 [-h] [-c email-addr] [-v]
-h this message
-c email-addr Email address to send a copy of the statistics report
-v verbose messages
EOC
exit 1
}
restart_dirsrv ()
{
pid=`$PS | grep dirsrv | grep -v grep | awk '{print $2}'`
debug "kill -USR2 $pid"
if kill -USR2 $pid ; then
debug "dirsrv signaled to re-open log file"
else
echo "*WARNING* dirsrv running as root; signal ignored"
fi
}
fatal()
{
echo ""
echo "${prog}: $1"
exit 1
}
debug()
{
if [ x$verbose = xy ] ; then
echo "$1"
fi
}
get_home()
{
if [ $# -ne 1 ] ; then
fatal "get_home: bad number of arguments"
fi
if p=`grep "^${1}:" /etc/passwd` ; then
echo $p | awk -F: '{print $6}'
elif p=`ypmatch $1 passwd` ; then
echo $p | awk -F: '{print $6}'
else
fatal "get_home: can't find home directory for $1"
fi
}
abort () {
echo "Problem with $0. Aborting";
exit -2;
}
# Please do not change is address.
# Use the -c flag to append additional addresses
dest="prospero-stats@archie.bunyip.com";
# Disable the users .mailrc file
MAILRC=/dev/null
export MAILRC
v="";
while [ $# -gt 0 ] ; do
case $1 in
-c) if [ $# -gt 1 ] ; then
shift;
dest="$dest,$1";
else
echo "E-mail address required for this flag"
usage;
fi ;;
-x) set -x;;
-v) verbose="y";
v="-v";;
-h) usage;;
*) echo "Unknown option [$1]";
usage;;
esac
shift
done
if gzip </dev/null >> /dev/null ; then
gzip="y";
else
gzip="n";
cat - << EOC
Note: \`gzip' not found on this system. This script will run nonetheless,
however please install it if you can, as we are using some features of \`gzip'
not available to \`compress'. Bunyip can assist if you need help.
EOC
fi
osname=`uname`
rel=`uname -r | sed 's/\..*$//'`
case $osname in
"SunOS")
tlink="-h"
if [ x$rel = x4 ] ; then
PS="/bin/ps aguxwww"
else
PS="/usr/ucb/ps aguxwww"
fi
;;
"AIX")
tlink="-L"
PS="/bin/ps -aef"
;;
esac
home=`get_home archie`
odirsrv=`$PS | grep dirsrv | grep -v grep | awk '{print $1}'`
debug "dirsrv owned by $odirsrv"
if [ "$odirsrv" = "root" ] ; then
# A truly atrocious hack. Need to have a configuration script for
# this stuff - lucb
eval `grep '^ARCHIE_USER' ../bin/mail_stats`;
id=`id | sed 's/(.*$//' | sed 's/^.*=//'`;
debug "Your uid is $id";
if [ $id -ne 0 ]; then
echo "*PROBLEM* Dirsrv is running as root. $0 must also run as root"
echo "*PROBLEM* Dirsrv is running as root. $0 must also run as root"|\
$MAIL -s "Problem with $0" $ARCHIE_USER
exit 2;
fi
fi
debug "Cleaning up archie log files in $home/logs"
cd $home/logs
if [ ! \( -d history -o $tlink history \) ] ; then
mkdir history || abort
fi
# Keep 32 days of archie and email logs
f=`ls *.log`;
for l in $f; do
$home/scripts/rotate $v -d $home/logs/history -c $l 32;
chown archie $l;
chgrp archie $l;
done
debug "Taking care of the prospero logs"
cd $home/pfs
if [ ! \( -d history -o $tlink history \) ] ; then
mkdir history || abort
fi
$home/scripts/rotate $v pfs.log
chown archie pfs.log
restart_dirsrv
# $home/scripts/eval-perf.pl < /pfs/pfs.log
debug "Generating prospero statistics"
cat /pfs/pfs.log.* | $home/scripts/prospero-stats.pl | \
$MAIL -s "Prospero Statistics Report" $dest
debug "Archiving prospero log"
if cat /pfs/pfs.log.* | $home/scripts/trimplog.pl $v -d /pfs/history -g $gzip ; then
debug "Trimming prospero log"
rm -f /pfs/pfs.log.*
fi
cd /pfs/history
debug "Clean history files older than six months"
find . -mtime +180 -print | xargs rm
# If gzip is not available, then compress the log files after 7
# days. DO NOT COMPRESS immediately. trimplog may append to an already
# existing log file. If gzip is available, compression will be automatic,
# as gzip allows concatenation of compressed items.
if [ $gzip = "n" ] ; then
debug "Compressing archived log files older than seven days"
find . -mtime +7 -print | xargs compress
fi