Jump to content

[UNIX] Usefull Cronjob collection


loki1991

Recommended Posts


  • Group:  Members
  • Topic Count:  11
  • Topics Per Day:  0.00
  • Content Count:  22
  • Reputation:   13
  • Joined:  01/07/12
  • Last Seen:  

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
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  210
  • Reputation:   10
  • Joined:  11/20/11
  • Last Seen:  

Thank you so much!!

Link to comment
Share on other sites

  • 3 months later...

  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  54
  • Reputation:   1
  • Joined:  02/21/12
  • Last Seen:  

thankyou more scripts to come bro :D

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  28
  • Reputation:   0
  • Joined:  02/17/12
  • Last Seen:  

Thank You! Bro.!

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  28
  • Topics Per Day:  0.01
  • Content Count:  353
  • Reputation:   70
  • Joined:  07/14/12
  • Last Seen:  

any link for this?

Edited by icabit
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  75
  • Topics Per Day:  0.02
  • Content Count:  2223
  • Reputation:   593
  • Joined:  10/26/11
  • Last Seen:  

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

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  28
  • Topics Per Day:  0.01
  • Content Count:  353
  • Reputation:   70
  • Joined:  07/14/12
  • Last Seen:  

ayt ill learn how to do that :D

thx brian

Link to comment
Share on other sites

  • 1 month later...

  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  44
  • Reputation:   9
  • Joined:  03/07/13
  • Last Seen:  

Thanx alot for the sharing!

Link to comment
Share on other sites

  • 4 weeks later...

  • Group:  Members
  • Topic Count:  30
  • Topics Per Day:  0.01
  • Content Count:  106
  • Reputation:   0
  • Joined:  11/16/11
  • Last Seen:  

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

Link to comment
Share on other sites

  • 9 months later...

  • Group:  Members
  • Topic Count:  11
  • Topics Per Day:  0.00
  • Content Count:  22
  • Reputation:   13
  • Joined:  01/07/12
  • Last Seen:  

Now the "markers" are variables.

Link to comment
Share on other sites

  • 3 months later...

  • Group:  Members
  • Topic Count:  30
  • Topics Per Day:  0.01
  • Content Count:  208
  • Reputation:   11
  • Joined:  05/31/12
  • Last Seen:  

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?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...