The problem is that we don't have EASY root access to servers. That's why being able to run logrotate without being root is very handy. This is what I did after following articles on the internet.
- Create a directory /home/techyman/logrotate with two files logrotate.conf and logrotate.status
- Put your logrotate configuration files there in logrotate.conf
/home/techyman/glassfish4/glassfish/domains/*/logs/*.log {
su techyman techyman
daily
copytruncate
missingok
rotate 30
compress
notifempty
dateext dateformat -%Y-%m-%d-%s
}
- Run a cron job
0 1 * * * /usr/sbin/logrotate -s /home/techyman/logrotate/logrotate.status /home/techyman/logrotate/logrotate.conf
This runs everyday at 1 AM.
To test every 1 second, just do * * * * * in cron job.
But it's not working. When I force it, it says "bad line at top in status file", otherwise no actions are being seen. I just see application.log alone.
How do I fix this issue? What am I doing wrong?
I removed notifempty and still it's not working.
I then removed su techyman techyman and still it's not working.
Finally manually doing this works. But the cron job still doesn't work.
/usr/sbin/logrotate -s /home/techyman/logrotate/logrotate.status
-f /home/techyman/logrotate/logrotate.conf
Output of head -5 logrotate.status
logrotate state -- version 2
"/home/techyman/glassfish4/glassfish/domains/b/logs/application.log" 2023-11-19-17:46:26
"/home/techyman/glassfish4/glassfish/domains/domain1/logs/application.log" 2023-11-19-17:46:26
"/home/techyman/glassfish4/glassfish/domains/e/logs/application.log" 2023-11-19-17:46:26
"/home/techyman/glassfish4/glassfish/domains/c/logs/application.log" 2023-11-19-17:46:26
I removed daily from logrotate.conf hoping it would fix the issue but it still doesn't work from cron.
head -5 /home/techyman/logrotate/logrotate.status. What is the output? (Please edit your question, don't write it as a comment.)-fis missing in the latter. It may be a typo, it may or may not be the problem, but you should fix it anyway.* * * * *that is every second, so every second (even without-fit should do the log rotation)cron, a cron job specified as* * * * *is every minute, not every second. (it's "each minute of each hour of each day of each month, and every weekday)