How best can logrotate be configured, on a per-user basis, to rotate files in the home directory of the user, under control of a per-user crontab -e?
Asked
Active
Viewed 2.5k times
1 Answers
36
Try this procedure:
create
/home/user/logrotatefoldermkdir /home/user/logrotatecreate
/home/user/logrotate/my.confconfiguration file with logrotate directive as you needcreate
/home/user/logrotate/cronjobto run logrotate every day at 2:30 AM (this is an example)30 2 * * * /usr/sbin/logrotate -s /home/user/logrotate/status /home/user/logrotate/my.conf > /dev/null 2>&1check your configuration file syntax:
logrotate -d /home/user/logrotate/my.confconfigure
crontabto runlogrotate(Warning: This removes existing entries in your crontab. Usecrontab -eto manually add the line from step 3 to an existing crontab):crontab /home/user/logrotate/cronjob
After this last command, logrotate will rotate file as described in /home/user/logrotate/my.conf and save log file status in /home/user/logrotate/status.
Use:
crontab -r # remove crontab activities for user
crontab -l # to list crontab activity for user
crontab -e # edit user crontab entries
jurgispods
- 203
Lety
- 6,099
-sparameter will avoiderror: error creating unique temp file: Permission denied. – Marco Marsala May 10 '16 at 08:18
– realtebo Aug 27 '20 at 07:48error: error creating output file /var/lib/logrotate/status.tmp: Permission denied-sparam solves the problem, so I can run as normal user, specifi my config file to execute and also using-sI can specify state file. Thanks, really – realtebo Aug 28 '20 at 12:47