General > Helpful posts

Bot Check on Linux

(1/4) > >>

Shelly:
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 &");
}

redman:
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 ...

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

[*]Works if you're running bots as:[/list]

--- Code: ---php -f StartBot.php <botname>
--- End code ---
[*]Logs are saved in the bot's logdir, with .log instead of .txt.
[/list]

The script:
--- Code: ---#!/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
--- End code ---

Example crontab:
--- Code: ---*/5 * * * * /home/user/bot_check.sh bots/org Botty 1
--- End code ---

Vain:
Could someone adapt this to AOC where there isnt a dimension?
I also dont run multiple folders for my bots...




--- Quote from: 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.

[*]Works if you're running bots as:[/list]

--- Code: ---php -f StartBot.php <botname>
--- End code ---
[*]Logs are saved in the bot's logdir, with .log instead of .txt.
[/list]

The script:
--- Code: ---#!/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
--- End code ---

Example crontab:
--- Code: ---*/5 * * * * /home/user/bot_check.sh bots/org Botty 1
--- End code ---

--- End quote ---

Shelly:

--- Quote from: 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...

--- End quote ---

Vain,

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

[*]Works if you're running bots as:[/list]

--- Code: ---php -f StartBot.php <botname>
--- End code ---
[*]Logs are saved in the bot's logdir, with .log instead of .txt.
[/list]

The script:
--- Code: ---#!/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
--- End code ---

Example crontab:
--- Code: ---*/5 * * * * /home/user/bot_check.sh bot_home Your_bot_name
--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version