LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   logrotate cron job not rotating certain logs (https://www.linuxquestions.org/questions/linux-software-2/logrotate-cron-job-not-rotating-certain-logs-4175455880/)

ashokkvnit 03-28-2013 03:35 AM

logrotate cron job not rotating certain logs
 
I added two scripts in "logrotate.d" directory for my application logs to be rotated.
This is the config for one of them:

Quote:

<myLogFilePath> {
compress
copytruncate
delaycompress
dateext
missingok
notifempty
daily
rotate 30
}
There is a "logrotate" script in "cron.daily" directory (which seems to be running daily as per cron logs):

Quote:

#!/bin/sh

echo "logrotate_test" >>/tmp/logrotate_test
#/usr/sbin/logrotate /etc/logrotate.conf >/dev/null 2>&1
/usr/sbin/logrotate -v /etc/logrotate.conf &>>/root/logrotate_error

EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0
The first echo statement is working.
But I find my application logs alone are not getting rotated, whereas other logs like httpd are getting rotated
And I also don't see any output in the mentioned "logrotate_error" file (has write permission for all users).

However the syslog says: "logrotate: ALERT exited abnormally with [1]"

But when I run the same "logrotate" in "cron.daily" script manually, everything seems working fine.

Why is it not rotating during daily cron schedule? Am I doing something wrong here?
It would be great if I get this much needed help.

acid_kewpie 03-28-2013 04:32 AM

"&>>" doesn't make sense. Certainly not in bash.

# echo blah &>> afile
-bash: syntax error near unexpected token `>'

just run the logrotate entry yourself:


/usr/sbin/logrotate -v /etc/logrotate.conf

and see what happens then.

ashokkvnit 03-28-2013 05:42 AM

Thanks for your reply.

I tried executing that script manually and checked that it's logging it's output (both stdout and stderr) in the mentioned file.
I don't know if that is to do something with bash version.
On 3.2.48, it gave the same error which you have mentioned, but on 4.1.2, where the logrotate script is running, it looks fine.

ashokkvnit 04-02-2013 08:32 AM

It looks like, it's because of selinux - the log files in my user home directory has restrictions imposed by selinux and the when logrotate script is run:

Quote:

SELinux is preventing /usr/sbin/logrotate from getattr access on the file /home/user/logs/application.log.

colucix 04-02-2013 10:44 AM

Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate. Please, follow discussion here: http://www.linuxquestions.org/questi...gs-4175455881/


All times are GMT -5. The time now is 10:56 AM.