Solved newsyslog(8) vs. custom shell script + cron(8)

I have a directory that is periodically populated with logs like that:
Code:
2026-03-18_22-56-00.log
2026-03-19_02-30-00.log
2026-03-22_02-30-00.log
2026-03-25_02-30-00.log
2026-03-25_17-08-16.log

I want to compress the files that are older than 7 days and I'm a little bit confused what tool would be appropriate for this task: newsyslog(8) or a custom script run by cron(8)?

If I understand correctly, newsyslog(8) is useful when you essentially have one 'main' log file (named like mail.log), which always contains the latest logs and when this file grows or ages, it becomes something like mail.log.0.xz and mail.log is trimmed.

It doesn't looks quite like my case, because in my model, my program already writes a separate log file with unique name. So I guess for my task it would be more appropriate to schedule cron(8) to run my custom shell script that will simply find(1) files that are old enough and compress them.

Am I right?
 
[…] I want to compress the files […]
With ZFS compression enabled I don’t even bother with manually compressing any files anymore. zfs get compression /var/log
[…] newsyslog(8) is useful when you essentially have one 'main' log file […]
That is my understanding, too.​
[…] in my model, my program already writes a separate log file with unique name. […]
So your program already does the rotation part. Uhm, maybe stop your program from doing that? Can you tell your program to use some prefix as a log file name?​
 
Back
Top