Debugging logrotate postrotate script

amazon s3amazon-web-servicesdebugginglogrotate

Following is my logrotate conf.

/mnt/je/logs/apache/jesites/web/*.log" {
        missingok
        rotate 0
        size 5M
        copytruncate
        notifempty
        sharedscripts
        postrotate
                /home/bitnami/.conf/compress-and-upload.sh /mnt/je/logs/apache/jesites/web/ web 
        endscript
}

And compress-and-upload.sh script,

#!/bin/sh
# Perform Rotated Log File Compression
tar -czPf $1/log.gz $1/*.1

# Fetch the instance id from the instance
EC2_INSTANCE_ID="`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id`"
if [ -z $EC2_INSTANCE_ID ]; then
echo "Error: Couldn't fetch Instance ID .. Exiting .."
exit;           
else    
        /usr/local/bin/s3cmd put $1/log.gz s3://xxxx/logs/$(date +%Y)/$(date +%m)/$(date +%d)/$2/$EC2_INSTANCE_ID-$(date +%H:%M:%S)-$2.gz
fi
# Removing Rotated Compressed Log File
rm -f $1/log.gz

The files are rotated, but shell script is not executed. I don't know how to debug the postscript.

Is there any logfile I chek to see if there is any permission issues.

If i directly execute the script from commandline file upload works.

Thanks.

Best Answer

logrotate usually runs as a cron job, and its errors end up being mailed to root. Have a look at /var/mail/root, or alternatively make sure that /etc/aliases directs root's mail somewhere sensible, and that your instance can in fact send mail.