#!/bin/sh
#
# new botchk  (for eggdrop 1.0)
#
# 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.  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/mydir/mybot"

# change this to the name of your bot's script in that directory:
botscript="mybot"

# change this to the nickname of your bot (capitalization COUNTS)
botname="Doofy"

########## you probably don't need to change anything below here ##########

cd $botdir
if test -r pid.$botname; then
  # there is a pid file -- is it current?
  botpid=`cat pid.$botname`
  if `kill -CHLD $botpid >/dev/null 2>&1`; then
    # it's still going
    # back out quietly
    exit 0
  fi
  echo ""
  echo "Stale pid.$botname file (erasing it)"
  rm -f pid.$botname
fi
echo ""
echo "Couldn't find the bot running.  Reloading it..."
echo ""
./$botscript
