I am using a script to monitor a service. I have added said script in crontab
. crontab
runs the script every one minute.
I have found this script online and it works pretty good, but it writes the logs to /var/mail/pi
and that file does not rotate.
These are the permissions for /var/mail
and /var/mail/pi
:
drwxrwsr-x 2 root mail 4096 Oct 15 13:48 mail
-rw-rw---- 1 pi mail 1425632 Oct 15 13:49 pi
In /etc/logrotate.conf
I have added:
/var/mail/pi {
rotate 7
daily
su pi mail
}
Running logrotate -v /etc/logrotate.conf
returns, among other rotating patterns, the following:
rotating pattern: /var/mail/pi after 1 days (7 rotations)
empty log files are rotated, old logs are removed
switching euid to 1000 and egid to 8
error: error switching euid to 1000 and egid to 8: Operation not permitted
error: error creating output file /var/lib/logrotate/status.tmp: Permission denied
Running sudo logrotate -v /etc/logrotate.conf
returns:
rotating pattern: /var/mail/pi after 1 days (7 rotations)
empty log files are rotated, old logs are removed
switching euid to 1000 and egid to 8
considering log /var/mail/pi
Now: 2019-10-15 14:46
Last rotated at 2019-10-15 14:35
log does not need rotating (log has been already rotated)
switching euid to 0 and egid to 0
Running logrotate -f /etc/logrotate.conf
with or without sudo
doesn't return any error regarding /var/mail/pi
but only sudo logrotate -f /etc/logrotate.conf
creates pi.1
and/or pi.2
and so on.
I have no idea if the rotating pattern works or not.
su pi mail
out. If the issue is the mode of the files it creates, use an explicitcreate
directive to set that, or usechmod
/chown
inpostrotate
. – goldilocks♦ Oct 15 '19 at 13:05su pi mail
? I have just checked and it made a new log file today. If I remove it, not evensudo logrotate -f /etc/logrotate.conf
will work. It returns:error: skipping "/var/mail/pi" because parent directory has insecure permissions
– GeorgicaFaraFrica Oct 16 '19 at 9:50create 666 pi mail
also returnsskipping "/var/mail/pi" because parent directory has insecure permissions
– GeorgicaFaraFrica Oct 16 '19 at 9:59chmod/chown
inpostrotate
if I don't know the name of the file ? It can be pi.1, pi.2, pi.3, pi.4, pi.5, pi.6, pi.7 ... – GeorgicaFaraFrica Oct 16 '19 at 10:04"pi.*"
, make sure it is enclosed in quotes) -- but I was wondering why it did not work as is and just had a closer look at your question: "I have no idea if the rotating pattern works or not". You need to determine that, because if it works runsudo
then it should work via systemcrontab
(not the pi user one); if you need to ask a question, "How can I tell if logrotate is working or not?", do so, but do it on our larger sibling site, Unix & Linux. The pi is not really relevant here. – goldilocks♦ Oct 16 '19 at 13:31