Sign in to follow this  
loki1991

[UNIX] Usefull Cronjob collection

Recommended Posts

Heyho,

I stopped my work on any ragnarok server. So this is a small farewell gift.

This small scripts can be used as Cronjob (http://en.wikipedia.org/wiki/Cronjob) to decrease you administrative work.

You normaly just have to change the config variables.

Script 1: Auto RO server restart when crashed
(should be started via cronjob every 5 minutes or less)

#!/bin/bash

###CONFIG START###
SERVER_USER="foo"
PATH_TO_RO="/home/bar/rathena/"
###CONFIG END###


ERROR=0
if [ "$(ps auxf | grep 'login-server' | grep -v 'grep')" == "" ]; then
        ERROR=1
fi
if [ "$(ps auxf | grep 'char-server' | grep -v 'grep')" == "" ]; then
        ERROR=1
fi
if [ "$(ps auxf | grep 'map-server' | grep -v 'grep')" == "" ]; then
        ERROR=1
fi
if [ $ERROR == 1 ]; then
        su $SERVER_USER | $PATH_TO_RO/athena-start restart
fi

Script 2: SQL Backup
(should be started every day)

 

#!/bin/bash

###CONFIG START###
PATH_TO_BACKUPS="/home/foo/backups"
DB_HOST="localhost"
DB_USER="foo"
DB_PASSWORD="secretpw"
WHICH_DATABASES="ragnarok"
USER_NAME="foo"
USER_GROUP="bar"
###CONFIG END###

find -P $PATH_TO_BACKUPS -maxdepth 1 -type f \( -name '*.sql' \) -ctime +15 -exec rm {} \;
mysqldump -h$DB_HOST -u$DB_USER -p$DB_PASSWORD --databases $WHICH_DATABASES > $PATH_TO_BACKUPS/$(date +%Y-%m-%d).sql
chown $USER_NAME:$USER_GROUP $PATH_TO_BACKUPS/$(date +%Y-%m-%d).sql

 

Script 3: Logs -> History DB

If you have the logs and ragnarok tables in the same database, you can may think of archive some of old logs to another database.
(should be started 2 times a month)

#!/bin/bash

###CONFIG START###
PATH_TO_RO="/home/bar/rathena"
DB_HOST="localhost"
DB_USER="bar"
DB_PASSWORD="secretpw"
DB_RAGNAROK_DATABASE="ragnarok"
DB_LOG_DATABASE="ragnarok-log"
###CONFIG END###


mysqldump -h$DB_HOST -u$DB_USER -p$DB_PASSWORD --compact --no-create-info $DB_RAGNAROK_DATABASE atcommandlog branchlog charlog chatlog npclog picklog zenylog > $PATH_TO_RO/temp.sql
mysql -h$DB_HOST -u$DB_USER -p$DB_PASSWORD -D$DB_RAGNAROK_DATABASE -e"DELETE FROM atcommandlog WHERE 1=1; DELETE FROM branchlog WHERE 1=1; DELETE FROM charlog WHERE 1=1; DELETE FROM chatlog WHERE 1=1; DELETE FROM npclog WHERE 1=1; DELETE FROM picklog WHERE 1=1; DELETE FROM zenylog WHERE 1=1;"
mysql -h$DB_HOST -u$DB_USER -p$DB_PASSWORD -D$DB_LOG_DATABASE < $PATH_TO_RO/temp.sql
rm $PATH_TO_RO/temp.sql
 

(before you start this script, you should insert a structure only dump into your history database)

 

I hope this may help you and the config is understandable.

Greetings,
Loki1991(before you start this script, you should insert a structure only dump into your history database)

Edited by loki1991
  • Upvote 7

Share this post


Link to post
Share on other sites

All of the Linux shell scripts are in QUOTE boxes in post #1.

  • Upvote 1

Share this post


Link to post
Share on other sites

Script 3: Logs -> History DB
(should be started 2 times a month)


Quote

#!/bin/bash
mysqldump -hDBSERVER_IP -uDB_USER -pDB_PASSWORD --compact --no-create-info RAGNAROK_DB atcommandlog branchlog charlog chatlog npclog picklog zenylog > PATH_TO_RO/temp.sql
mysql -hDBSERVER_IP -uDB_USER -pDB_PASSWORD -DRAGNAROK_DB -e"DELETE FROM atcommandlog WHERE 1=1; DELETE FROM branchlog WHERE 1=1; DELETE FROM charlog WHERE 1=1; DELETE FROM chatlog WHERE 1=1; DELETE FROM npclog WHERE 1=1; DELETE FROM picklog WHERE 1=1; DELETE FROM zenylog WHERE 1=1;"
mysql -hDBSERVER_IP -uDB_USER -pDB_PASSWORD -DHISTORY_DB < PATH_TO_RO/temp.sql
rm PATH_TO_RO/temp.sql

(before you start this script, you should insert a structure only dump into your history database)

how to make crontab by here 
* * * * * 
(before you start this script, you should insert a structure only dump into your history database) and also this HOW

Share this post


Link to post
Share on other sites

Now the "markers" are variables.

 

 

hello how would i apply this? i haven't done any cronjobs and as i see the comment it is really good can you teach me how?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this