BeBot - An Anarchy Online and Age Of Conan chat automaton

General => Helpful posts => Topic started by: Shelly on September 05, 2005, 03:50:16 pm

Title: Bot Check on Linux
Post by: Shelly on September 05, 2005, 03:50:16 pm
I created a small perl script to make sure my bot is running and haven't seen anything like it on the boards, so I am sharing it here.

Shelly

bot_check.pl
#!/usr/bin/perl

# Author: Shelly
# Notes:
# 1. Replace all "YourBotName" with what ever the name of your bot.
# 2. Replace your_account\@your_mail_host with the email address you want to recieve your
# logs and notifications at.
# 3. I also place the bot in it's own directory (YourBotName), but save the logs in bebot's home directory.
# This way I can run multiple bots.
# 4. Crontab Entry for Fedora Core/ Vixie Cron
# 0/10 * * * * cd /home/bebot; ./bot_check.pl >/dev/null

#
##
### Check for AO Bots and restart if necessary
##
## bebot 12007 11929 0 11:45 pts/0 00:00:00 php -f YourBotName/start.php
#

$mdate = `date +%b-%d-%Y`;

$z = `ps -ef |grep YourBotName |grep -v grep`;
chop($z);
if ($z eq "")
{
system("mail your_account\@your_mail_host -s \"Starting YourBotName bot on web1\" </home/bebot/YourBotName.log");
system("mv /home/bebot/YourBotName.log /home/bebot/YourBotName.log-${mdate}");
system("cd /home/bebot; /usr/local/bin/php -f /home/bebot/YourBotName/start.php > /home/bebot/YourBotName.log &");
}
Title: Bot Check on Linux
Post by: redman on September 06, 2005, 01:28:15 pm
if you can check, you should be able to autorestart it with that script either or ?

sorry my fault it restarts it automatically as far asi can see now.
cool script thx very much will try it out this weekend ...
Title: Re: Bot Check on Linux
Post by: laen on February 16, 2008, 07:42:55 pm
Made a bash script, and since i'm running multiple bots, check the botname, and bot dir.

Code: [Select]
php -f StartBot.php <botname>
The script:
Code: [Select]
#!/bin/bash
### bot crontab script by [email protected]
###
### run as <script_name> <bot_dir> <bot_name> <bot_dimension (1, 2 or 3)>

# code
if [ ! "`ps x -o args | grep "php -f StartBot.php "$2"" | grep -v grep | cut -d " " -f 4`" = "$2" ]; then
        cd "$HOME"/"$1"/; php -f StartBot.php $2 >> log/`echo "$2" | tr "A-Z" "a-z"`\@RK"$3"/`date +%Y-%m-%d.log` 2>&1 &
fi

Example crontab:
Code: [Select]
*/5 * * * * /home/user/bot_check.sh bots/org Botty 1
Title: Re: Bot Check on Linux
Post by: Vain on January 04, 2009, 07:39:18 am
Could someone adapt this to AOC where there isnt a dimension?
I also dont run multiple folders for my bots...



Made a bash script, and since i'm running multiple bots, check the botname, and bot dir.

  • Works if you're running bots as:
Code: [Select]
php -f StartBot.php <botname>
  • Logs are saved in the bot's logdir, with .log instead of .txt.

The script:
Code: [Select]
#!/bin/bash
### bot crontab script by [email protected]
###
### run as <script_name> <bot_dir> <bot_name> <bot_dimension (1, 2 or 3)>

# code
if [ ! "`ps x -o args | grep "php -f StartBot.php "$2"" | grep -v grep | cut -d " " -f 4`" = "$2" ]; then
        cd "$HOME"/"$1"/; php -f StartBot.php $2 >> log/`echo "$2" | tr "A-Z" "a-z"`\@RK"$3"/`date +%Y-%m-%d.log` 2>&1 &
fi

Example crontab:
Code: [Select]
*/5 * * * * /home/user/bot_check.sh bots/org Botty 1
Title: Re: Bot Check on Linux
Post by: Shelly on January 04, 2009, 10:37:42 am
Could someone adapt this to AOC where there isnt a dimension?
I also dont run multiple folders for my bots...

Vain,

The below should work for you: (but I don't have any AOC bots so not positive)

Code: [Select]
php -f StartBot.php <botname>
The script:
Code: [Select]
#!/bin/bash
### bot crontab script by [email protected]
### Modified by Shelly
### run as <script_name> <bot_dir> <bot_name>

# code
if [ ! "`ps x -o args | grep "php -f StartBot.php "$2"" | grep -v grep | cut -d " " -f 4`" = "$2" ]; then
        cd "$HOME"/"$1"/; php -f StartBot.php $2 >> log/`echo "$2" | tr "A-Z" "a-z"`/`date +%Y-%m-%d.log` 2>&1 &
fi

Example crontab:
Code: [Select]
*/5 * * * * /home/user/bot_check.sh bot_home Your_bot_name
Title: Re: Bot Check on Linux
Post by: laen on May 07, 2009, 02:40:54 pm
Updated my scripts a bit so it minimizes the processes that run, and doesn't end up in a defunct launcher shell script.

Crontab:
Code: [Select]
*/5 * * * * nohup /path/to/launcher Botname 2>/dev/null 1>&2 &
Launcher:
Code: [Select]
[[ ! $(ps x -o args | grep "/usr/bin/php ./Main.php $1" | grep -v grep | cut -d " " -f 3) = $1 ]] && {
    cd $HOME/dit/to/bot/
    exec /usr/bin/php ./Main.php $1 2>/dev/null 1>&2
}

Resulting processes (ps x):
Code: [Select]
  PID TTY      STAT   TIME COMMAND
 7703 pts/5    S      0:17 /usr/bin/php ./Main.php Botname
Title: Re: Bot Check on Linux
Post by: Sinaii on September 02, 2009, 01:16:04 am
Hello, what the code, for a bot check every 1hour on debian 5 ?

I'm sorry i'm very low skilled in linux system.
Title: Re: Bot Check on Linux
Post by: Sylfarin on October 14, 2009, 04:38:37 pm
Hello, what the code, for a bot check every 1hour on debian 5 ?

I'm sorry i'm very low skilled in linux system.

Not sure your question been answered or if you've figured it out yet here is what your crontab should look like:
Code: [Select]
0 * * * * yourcommand

If this doesnt work on your version, which I doubt, you might want to try * */1 * * * instead.
Title: Re: Bot Check on Linux
Post by: Shelly on October 15, 2009, 11:15:43 pm
You can also use a line like:
Code: [Select]
0 * * * * nohup /path/to/launcher Botname 2>/dev/null 1>&2 &in your crontab. This runs the launcher every hour on the hour.

Or if you want to get real specific:
Code: [Select]
0 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 * * * nohup /path/to/launcher Botname 2>/dev/null 1>&2 &This runs the launcher every hour on the hour also.
Title: Re: Bot Check on Linux
Post by: Zweiblum on January 17, 2011, 11:29:04 am
hmm sorry i realy new to ubuntu hosting here.

I used the last updated script from lean.

in 'crontab -e'
Code: [Select]

# m h  dom mon dow   command

#-----------------------------------------------------------------
# Shell variable for cron
SHELL=/bin/bash
# PATH variable for cron
PATH=/usr/local/bin:/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/bin/X11
#M   S     T M W   Befehl
#-----------------------------------------------------------------
* * * * * nohup /home/user/bebot/bebot_old/bebot/bot_check.sh botname 2>/dev/null 1>&2 &
* * * * * echo hello
#-----------------------------------------------------------------


i gave the bot_chech.sh chmod +x

but still its not working.

any ideas?

and is it possible to start a bot in a new "screen" using screen -S or screen -r ?
Title: Re: Bot Check on Linux
Post by: Yite on January 17, 2011, 12:56:32 pm
I run my bots in screens to prevent them stopping when my ssh session dies.
Title: Re: Bot Check on Linux
Post by: Zweiblum on January 17, 2011, 01:14:37 pm
yes, i would liek to know if botcheck can start the bots in screens

And i would be glad to here if i setup up the bot_check script right.

Because when i shutdown the bot, the crontab isnt restarting it.
Title: Re: Bot Check on Linux
Post by: Zweiblum on January 17, 2011, 07:02:40 pm
Launcher:
Code: [Select]
[[ ! $(ps x -o args | grep "/usr/bin/php ./Main.php $1" | grep -v grep | cut -d " " -f 3) = $1 ]] && {
    cd $HOME/dit/to/bot/
    exec /usr/bin/php ./Main.php $1 2>/dev/null 1>&2
}

isnt there a "if" missing at the start pf the script?
Title: Re: Bot Check on Linux
Post by: Zweiblum on January 19, 2011, 02:36:37 pm
Made a bash script, and since i'm running multiple bots, check the botname, and bot dir.

  • Works if you're running bots as:
Code: [Select]
php -f StartBot.php <botname>
  • Logs are saved in the bot's logdir, with .log instead of .txt.

The script:
Code: [Select]
#!/bin/bash
### bot crontab script by [email protected]
###
### run as <script_name> <bot_dir> <bot_name> <bot_dimension (1, 2 or 3)>

# code
if [ ! "`ps x -o args | grep "php -f StartBot.php "$2"" | grep -v grep | cut -d " " -f 4`" = "$2" ]; then
        cd "$HOME"/"$1"/; php -f StartBot.php $2 >> log/`echo "$2" | tr "A-Z" "a-z"`\@RK"$3"/`date +%Y-%m-%d.log` 2>&1 &
fi

Example crontab:
Code: [Select]
*/5 * * * * /home/user/bot_check.sh bots/org Botty 1


Hi,
i got this script running now, with a small modification as im not starting the bots with -f parameter.
The newer version doesnt work as mentioned in my other post.

Does someone can tell me how i can now start the bots in a new "screen"  to connect to it and see whats going on?

thx

Title: Re: Bot Check on Linux
Post by: Kentarii on January 19, 2011, 05:47:21 pm
Try starting with this:
Code: [Select]
screen -S "bebot" -m -d bash -c 'cd ~/bebot/; php -f StartBot.php'
List your screens
Code: [Select]
screen -ls
Reconnect to your screen
Code: [Select]
screen -r bebot
Title: Re: Bot Check on Linux
Post by: Zweiblum on January 21, 2011, 05:49:02 pm
hey, but when i do
Code: [Select]
screen -SThe bot will start everytime in a new screen, this might cause a problem if the bot has to start very often and then i would have many screens with nothing in it.

Would have to be something like if no screen then screen -S, if screen then screen -r or something like this.

PS: anyone got the 2nd script from lean running? still using the 1st one and he said the 2nd would be better, but cant see why :p

thx for any help, im realy new to ubuntu hosting and on old windows days i got a easy to use tool for it ;)
SimplePortal 2.3.7 © 2008-2024, SimplePortal