I have a tomcat
server that generates access logfiles on a daily rotation.
To clean them up every X days, I tried configuring the following crontab -e
:
@weekly find /var/log/tomcat8/localhost_access_log.*.txt -mtime +10 -delete
Problem: I'm getting a Permission denied
error running this. Because the /var/log/tomcat8
folder has tomcat:tomcat
user:group permissions, and I'm logged in as a different one.
So, how could I best create a cronjob that has permissions to delete those files?
Or should I just add the crontab via sudo crontab -e
?
You could fix that using
sudo crontab -e
, sinceroot
will have sufficient permissions.But
logrotate
seems to be the tool to rotate logs (and is most likely already in use in your system).Have a look in
/etc/logrotate.d/
and try to find iftomcat
already uses it.In order to run
crontab
which can access files owned by usertomcat
you can execute the command as usertomcat
Run
crontab
as usertomcat
using: