#!/bin/sh
#
# new botchk  (for eggdrop 1.0[m-o] + FreeBSD )
#
# This is a script suitable for use in a crontab.  It checks to make sure
# your bot is running.  YOU NEED A SEPARATE CRON JOB FOR EACH BOT-user.  If 
# your bot isn't found, it'll try to start it back up.
#
# You'll need to edit this script for your bot.
#
# To check for your bot every 10 minutes, put the following line in your
# crontab:
#    0,10,20,30,40,50 * * * *   /home/mydir/botchk
#

# change this to the directory you run your bot from:
botdir=${HOME}/mybot
eggdrop="/usr/local/bin/eggdrop"


########## you probably don't need to change anything between lines ##########
testbot() {
   local botpid
   local runpid
   local botnick
   local botscript
   botnick=$1
   botscript=$2
   if test -r pid.${botnick}; then
      botpid=`cat pid.${botnick}`
      runpid=`ps ${botpid} | tail +2 | awk '-F ' '{print $1;}'`
      if test "X${botpid}" != "X${runpid}"; then
         /usr/bin/logger -i -p daemon.warning -t $botnick found dead, restarting
         ./${eggdrop} ./${botscript}
      fi
   else
      /usr/bin/logger -i -p daemon.warning -t $botnick found dead, starting
      ./${eggdrop} ./${botscript}
   fi
}

cd $botdir
##############  Configure calls here for each bot  ##############
#### For each bot... configure a call ...
####  If bots are to run as different users, they MAY require different 
####  cron events.  It is also possible to make the botscripts suid, and
####  run as root - but this is quite dangerous, as it offers the prospects
####  of unrestricted TCL by that user as root, through administrative over-
####  sight. 
# testbot   Botnick   botscript
# =======   =======   =========
  testbot   FBSDbot    FBSDbot
