JBoss logs can take up gigabytes of space. The logrotation works well, however, there is no (not that I could find) means to compress in realtime. However, with a little work, this may be accomplished with a cron job.

I am not going to go into too much detail or background, there are many sites that do this well. However, I will source the sites that inspired this effort.

This is tested on CentOS 5.5 using JBoss 5.1.0 GA

I want to automate the compression of JBoss logs, then move these logs to another location after a period of time has passed.

Create the script.

gedit jboss-logs.sh

Copy the following into the jboss-logs.sh, modify where necessary.

#!/bin/bash
LOGS=/usr/local/jboss/server/default/log/
LOGBACK=/usr/local/jboss/server/default/backup/
INFOLOG="server.log"
ERRORLOG="error.log"
BOOTLOG="boot.log"

# gzip files last modify at least 1 hour ago
find $LOGS -mmin +61 -not -name "$INFOLOG" -not -name "$ERRORLOG" -not -name "$BOOTLOG" | xargs gzip -f

# move all logs older than 15 days
find $LOGS -mtime +15 -not -name "$INFOLOG" -not -name "$ERRORLOG" -not -name "$BOOTLOG" -print0 | xargs -0 -I xxx mv xxx $LOGBACK

Save the script, then make it executable.

chmod +x jboss-logs.sh

The script can manually be executed.

./jboss-logs.sh

Or, create a cron job to automate the process. I wanted a cron job to run at 12:05 AM everyday. To create a cron job, create a text file.

gedit jboss-logs.txt

Copy the following into it and make sure to press ENTER to start a new line:

5 0 * * * /usr/local/jboss/server/default/backup/logs.sh

jboss-logs

Save the file. Then create a cron job.

crontab /root/jboss-logs.txt

It can be verified to exist with the following command.

crontab -l

crontab-e

Done. The result should be an automated task to compress JBoss logs and move then after so many days to another location at 12:05 AM.

Resources
What is a cronjob, and how do I use it?
Excluding files in FIND results
xargs
How do I add jobs to cron under Linux or UNIX oses?
find

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...
      Print This Post       Print This Post       Email This Post       Email This Post

Related Articles57 views