collapse collapse
* User Info
 
 
Welcome, Guest. Please login or register.
* Search

* Board Stats
  • stats Total Members: 989
  • stats Total Posts: 18363
  • stats Total Topics: 2500
  • stats Total Categories: 7
  • stats Total Boards: 35
  • stats Most Online: 1144

Author Topic: Bot Check on Linux  (Read 21093 times)

0 Members and 1 Guest are viewing this topic.

Offline Shelly

  • BeBot Apprentice
  • ***
  • Posts: 192
  • Karma: +0/-0
Bot Check on Linux
« 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 &");
}

Offline redman

  • BeBot Rookie
  • *
  • Posts: 1
  • Karma: +0/-0
Bot Check on Linux
« Reply #1 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 ...

Offline laen

  • BeBot User
  • **
  • Posts: 24
  • Karma: +0/-0
Re: Bot Check on Linux
« Reply #2 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:
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
« Last Edit: February 17, 2008, 09:15:34 pm by lcidw »

Offline Vain

  • BeBot User
  • **
  • Posts: 57
  • Karma: +0/-0
Re: Bot Check on Linux
« Reply #3 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

Offline Shelly

  • BeBot Apprentice
  • ***
  • Posts: 192
  • Karma: +0/-0
Re: Bot Check on Linux
« Reply #4 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)

  • 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]
### 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

Offline laen

  • BeBot User
  • **
  • Posts: 24
  • Karma: +0/-0
Re: Bot Check on Linux
« Reply #5 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

Offline Sinaii

  • BeBot Rookie
  • *
  • Posts: 3
  • Karma: +0/-0
Re: Bot Check on Linux
« Reply #6 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.

Offline Sylfarin

  • BeBot Rookie
  • *
  • Posts: 10
  • Karma: +0/-0
Re: Bot Check on Linux
« Reply #7 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.

Offline Shelly

  • BeBot Apprentice
  • ***
  • Posts: 192
  • Karma: +0/-0
Re: Bot Check on Linux
« Reply #8 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.
« Last Edit: October 15, 2009, 11:20:24 pm by Shelly »

Offline Zweiblum

  • BeBot Apprentice
  • ***
  • Posts: 135
  • Karma: +0/-0
Re: Bot Check on Linux
« Reply #9 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 ?

Offline Yite

  • BeBot Apprentice
  • ***
  • Posts: 152
  • Karma: +0/-0
    • Niflheim - Crom
Re: Bot Check on Linux
« Reply #10 on: January 17, 2011, 12:56:32 pm »
I run my bots in screens to prevent them stopping when my ssh session dies.
-Yite [Crom]

Offline Zweiblum

  • BeBot Apprentice
  • ***
  • Posts: 135
  • Karma: +0/-0
Re: Bot Check on Linux
« Reply #11 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.
« Last Edit: January 17, 2011, 01:24:57 pm by Zweiblum »

Offline Zweiblum

  • BeBot Apprentice
  • ***
  • Posts: 135
  • Karma: +0/-0
Re: Bot Check on Linux
« Reply #12 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?

Offline Zweiblum

  • BeBot Apprentice
  • ***
  • Posts: 135
  • Karma: +0/-0
Re: Bot Check on Linux
« Reply #13 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


Offline Kentarii

  • BeBot Apprentice
  • ***
  • Posts: 153
  • Karma: +0/-0
    • AoC>TV
Re: Bot Check on Linux
« Reply #14 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

 

* Recent Posts
[AoC] special char for items module by bitnykk
[February 09, 2024, 09:41:18 pm]


0.8.x updates for AoC by bitnykk
[January 30, 2024, 11:16:08 pm]


0.8.x updates for AO by bitnykk
[January 30, 2024, 11:15:37 pm]


BeBot still alive & kicking ! by bitnykk
[December 17, 2023, 12:58:44 am]


Bebot and Rasberry by bitnykk
[November 29, 2023, 11:04:14 pm]

* Who's Online
  • Dot Guests: 388
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.
* Forum Staff
bitnykk admin bitnykk
Administrator
Khalem admin Khalem
Administrator
WeZoN gmod WeZoN
Global Moderator
SimplePortal 2.3.7 © 2008-2024, SimplePortal