Tikejhya: Ashish Nepal

Knowledgebase

Category: Log Rotate

IPTables Logging

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

#Log All DB Connections
-A INPUT -p tcp -m tcp –dport 3306 -m limit –limit 5/min –limit-burst 7 -j LOG –log-prefix “*DB_ATTEMPT*”

# Logging much else clutters up the screen.
#kern.* /dev/console
kern.* /var/log/kernel

Debugging logrotate

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

How to debug logrotate?

logrotate -dv /etc/logrotate.conf

LOG Manage

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

#!/bin/bash
#### Directory variable####
LOG_DIR=’/data/logs/local_backup/’
HOST_NAME=`hostname -s`
LOG_LOCATION=’data/logs/something’
YYYY=`date +%Y`
MM=`date +%m –date=’1 month ago’`
FULL_PATH=$LOG_DIR$LOG_LOCATION
echo “$FULL_PATH”
for file in $FULL_PATH;do
file=`ls -d $FULL_PATH/*`
for i in $file; do
FINAL_PATH=$i/
mkdir -p $FINAL_PATH$YYYY/$MM
mv $FINAL_PATH*-$YYYY-$MM $FINAL_PATH$YYYY/$MM

done
done
#################

And if we need to add things like if it was last month of the year..
it would show as 12 and YYYY pointing to same year.

solution:

#!/bin/bash
#### Directory variable####
LOG_DIR=’/data/logs/local_backup/’
HOST_NAME=`hostname -s`
LOG_LOCATION=’data/logs/bidsys’
# YYYY=`date +%Y`
MM=`date +%m –date=’1 month ago’`
FULL_PATH=$LOG_DIR$LOG_LOCATION
echo “$FULL_PATH”
if [ “$MM” = “12” ]; then
echo “It was previous Year”
YYYY=`date +%Y –date=’1 year ago’`
echo “Now YYYY = $YYYY”
else
YYYY=`date +%Y`
fi
for file in $FULL_PATH;do
file=`ls -d $FULL_PATH/*`
for i in $file; do
FINAL_PATH=$i/
mkdir -p $FINAL_PATH$YYYY/$MM
mv $FINAL_PATH*-$YYYY-$MM $FINAL_PATH$YYYY/$MM

done
done

Rabbitmq Log rotate

Rotating rabbitmq log files.

rabbitmqctl rotate_logs

Logrotate and move to backup directory

If you wish to backup old logs using olddir in logrotate it may create problem while giving separate partition for backup.

Logrotate and move to backup directory

Firstly i would suggest you to remove /var/log/messages from /etc/logrotate.d/syslog

vi /etc/logrotate.d/syslog

remove line /var/log/messages

vi /etc/logrotate.d/messages

Paste belwo given.

/var/log/messages
{
        daily
        rotate 10
        missingok
        postrotate
        /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
        /bin/kill -HUP `cat /var/run/rsyslogd.pid 2> /dev/null` 2> /dev/null || true
        /var/log/messagesrotate.sh || true
        endscript
}

::::::::::::::::::::: Script to run in Postrotate :::::::::::::::::::::::::::::::

#!/bin/bash
LogDate=$(date +"%s")
mv /var/log/messages.1 /data/logs/local_backup/var/log/messages/messages.$LogDate
gzip /data/logs/messages.$LogDate
exit

Powered by WordPress & Theme by Anders Norén