#! /bin/sh
#
# This program exists to be called from crontab so that it can call
# AQsend as a non-privileged user.
#
PATH=/adobe/server/bin:/usr/local/bin:/usr/ucb:/usr/bin:/bin:
export PATH
Log=/adobe/server/requestqueue/out.log
#OKLOAD=250
OKLOAD=400
OKSIZE=55000

trap "rm -f /usr/tmp/*.$$" 0 1 2 3 15
trap "echo `date`: error from AQcrontab >> $Log; exit" 1 2 3 15

# Don't do this if the load on adobe 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  '^adobe' > /usr/tmp/AQcrontab.$$
### if grep -s ' up ' /usr/tmp/AQcrontab.$$
### then

uptime > /usr/tmp/AQcrontab.$$

# mail gateway is up
    LOAD15MIN=`sed -e 's/.* \([^ ]*\)$/\1/' -e 's/\.//g' /usr/tmp/AQcrontab.$$`
    if [ $LOAD15MIN -gt $OKLOAD ]
    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 $OKSIZE
glogg
    else
	AQsend $OKSIZE
    fi
### else
# mail gateway is down
##    echo "`date`" AQcrontab: adobe down >> $Log
##    exit
### fi
