#! /bin/sh
#
# This program exists to be called from crontab so that it can call
# AQsend as a non-privileged user.
#
PATH=/aeneas/ftp/archive/bin:/usr/local:/bin:/usr/ucb:/usr/bin
export PATH
Log=/aeneas/ftp/archive/requestqueue/out.log

trap "rm -f /tmp/*.$$; exit" 0 1 2 3 15

# Don't do this if the load on aeneas is too high. /bin/test can only
# handle integers, so edit out the decimal point and multiply by 100.
# If you're trying to run this someplace besides a BSD system, what all this
# code is trying to do is determine whether or not the mail gateway is up, and
# if it up to determine what its load factor is.

ruptime | grep  '^aeneas' > /tmp/AQcrontab.$$
if grep -s ' up ' /tmp/AQcrontab.$$
then
# mail gateway is up
    LOAD15MIN=`sed -e 's/.* \([^ ]*\)$/\1/' -e 's/\.//g' /tmp/AQcrontab.$$`
    if [ $LOAD15MIN -gt 250 ]
    then
	echo "`date`" AQcrontab: load factor $LOAD15MIN >> $Log
	exit
    fi
    
    # The load factor is low enough. 
    ID=`whoami`
    if [ "$ID" = "root" ]
    then
	su daemon << glogg
	AQsend 25000
glogg
    else
	AQsend 25000
    fi
else
# mail gateway is down
    echo "`date`" AQcrontab: aeneas down >> $Log
    exit
fi
