Logrotate without root user access not working

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.

  1. Create a directory /home/techyman/logrotate with two files logrotate.conf and logrotate.status
  2. Put your logrotate configuration files there in logrotate.conf
/home/techyman/glassfish4/glassfish/domains/*/logs/*.log {
        

        daily
        copytruncate
        missingok
        rotate 30
        compress
        dateext dateformat -%Y-%m-%d-%s
}
  1. 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 removed su techyman techyman and it it still not working.

The first thing is to know if the script runs when you execute it in your terminal, if it doesn't, solve that before trying in batch mode
Next, if it does, but not when calls by cron, go and look the cron logs, but most certainly you have an issue with your environment, remember cron is dumb... in other words you have something in your environment when you connect as user techyman that cron ignores and needs desperately...

Since your cron from what I understand is run by the user, the su will just add possibly more issues, you don't need it...

cron when is invoked opens an sh as the user, only it does not read your .profile, so it knows nothing of your env. and has a minimalistic PATH set...

See the changes I made to logrotate, still not working but it works when forced from command line.

As I already mentioned in my previous post, if it works in command line, you as user have in your profile something cron needs... you have set something in your environment that is needed by cron to execute what you want, it can be its the path, libpath or variables that are set etc...

It only works when I set -f option in command line, it doesn't work normally like that. And it should not be like that?

Something wrong here? Empty it with

: > /home/techyman/logrotate/logrotate.status
1 Like

Try adding -d (debug) and -v (verbose) flags to your logrotate command , those will provide more detail.