1

A Linux service is creating a huge log file.

At the moment I am keeping it under control using cron (every X minutes I reduce it to the last X lines):

*/5 * * * * root  echo "$(tail -n 1000 /var/log/XXX/logger_file.log)" > /var/log/XXX/logger_file.log

Is there any other way to do the job in a cleaner way?

The first line, after the cut, can even be damaged if the chars cut is size based (i.e. keep the last 1024 bytes).

Of course I cannot modify the service itself to keep quiet.

5

Have you tried logrotate? man logrotate

Here is a guide that could help. How to Use logrotate to Manage Log Files

1
  • I hoped there is a setting somewhere to avoid the use of external commands. If it was system managed it would have dropped extra bytes as soon as the maximum file size was reached, instead of a temporal check with an extra command in cron. Logrotate is powerful indeed. Thank you. – Alex Poca Nov 10 '17 at 10:35
1

curtail limits the size of a program's output and preserves the last X KB (200 MB in this example) of output with the following command:

run_program | curtail -s 200M myprogram.log

https://github.com/Comcast/Infinite-File-Curtailer

NOTE: I'm the maintainer of the above repo. Just sharing the solution...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.