#! /bin/sh

# included as a subroutine in runfactor; touches the .run file, keeps
# checkrun in the at queue; sleeps for a few minutes
# If you have user-level cron files, you can run checkrun out of your
# cron file once an hour or so, and then you can cut this file down to:
#    touch $run
#    sleep $TICKSEC

touch $run
if test ${now-x} -eq ${now400-x}
then
# if you have trouble with formatted date, use the following instead:
# now=`date | awk '{ print $4; }' | awk -F: '{print $1 $2;}'`
  now=`date +%H%M`
  now110=`expr '(' $now + 110 ')' '%' 2400`
  if test `expr $now110 '%' 100` -ge 60
  then
    now110=`expr '(' $now110 '+' 40 ')' '%' 2400`
  fi
  at $now110 < $docheck >/dev/null 2>&1
  now400=`expr '(' $now + 400 ')' '%' 2400`
  at $now400 < $docheck >/dev/null 2>&1
elif test ${now-x} -eq ${now110-x}
then
  now110=`expr '(' $now + 110 ')' '%' 2400`
  if test `expr $now110 '%' 100` -ge 60
  then
    now110=`expr '(' $now110 '+' 40 ')' '%' 2400`
  fi
  at $now110 < $docheck >/dev/null 2>&1
fi
sleep $TICKSEC
now=`expr $now '+' $TICKLEN`
if test `expr $now '%' 100` -ge 60
then
  now=`expr '(' $now '+' 40 ')' '%' 2400`
fi
