Thursday, December 11, 2008

Rotate IBM HTTP Server / Plugin logs

The script has been tested on Solaris environment

rotate_http_logs.sh
-----------------------------
#!/usr/bin/bash -x

# Define variables. These variables can also be defined in .profile and the profile can be sourced
HOST=servernamegoeshere
IHS_ROOT=/opt/IBM/HTTPServer
IHS_BIN=$IHS_ROOT/bin
IHS_CONF=$IHS_ROOT/conf
IHS_LOGS=$IHS_ROOT/logs
PLUGIN_ROOT=$IHS_ROOT/Plugins
PLUGIN_CONF=$PLUGIN_ROOT/config
PLUGIN_LOGS=$PLUGIN_ROOT/logs

# Rotate IBM HTTP Plugin Log
cd $PLUGIN_LOGS/$HOST
SOURCE_FILE=http_plugin.log
TARGET_FILE=http_plugin.log.`date +%Y-%m-%d`
cp $SOURCE_FILE $TARGET_FILE
touch $SOURCE_FILE

# Rotate IBM HTTP Access Log
cd $IHS_LOGS
SOURCE_FILE=error_log
TARGET_FILE=error_log.`date +%Y-%m-%d`
sudo touch $SOURCE_FILE

# Rotate IBM HTTP Error Log
SOURCE_FILE=access_log
TARGET_FILE=access_log.`date +%Y-%m-%d`
sudo touch $SOURCE_FILE

#sudo is used for web servers if the service is run as non root

Create a cron job
-------------------------
0 23 * * * /var/adm/scripts/rotate_http_logs.sh

No comments: