#! /bin/sh # dir for the bot botdir="/home/netsniper/bot" # bot pid file pidfile=".irpg.pid" # bot name botname="irpg" # bot command line botscript="perl bot.v3.1.2.pl" # userfile userfile="bot.v3.1.2.user" #################################### # Do the work: cd $botdir #check for pid if test -r $pidfile then #there is a pid file - is it current? botpid=`cat $pidfile` if `kill -CHLD $botpid >/dev/null 2>&1` then # all is good, exit quietly exit 0 fi echo "" echo "Stale $pidfile file, erasing..." rm -f $pidfile fi if test -r CANSTART.$botname then if test -r $userfile || test -r $userfile~new || test -r $userfile~bak then echo "" echo "Userfile found, removing check file 'CANTSTART.$botname'..." rm -f CANTSTART.$botname fi fi # test if we have run botchk previously and didn't find a userfile if test ! -f CANTSTART.$botname then echo "" echo "Couldn't find bot 'botname' running, reloading..." echo "" #check for userfile and reload bot if found if test -r $userfile then #it's there - load the bot $botscript exit 0 else if test -r $usefile~new then # Bot fucked up echo "Userfile missing. Using last saved userfile..." mv -f $usefile~new $userfile $botscript exit 0 else if test -r $userfile~bak then # Userfile is missing, use backup userfile..." cp -f $userfile~bak $userfile $botscript exit 0 else echo "No userfile. Could not reload the bot..." echo "no userfile" > CANTSTART.$botname exit 1 fi fi fi fi fi exit 0