Is it possible to trim the log file that the daemon opened without the daemon closing the file?

I have a daemon writing to a log file that eventually fills the disk. Is there a way to periodically limit the size of the log file without stopping the daemon without changing the code in it? SIGHUP kills the demon.

+3
source share
3 answers

The usual trick:

echo -n > /var/log/name.log

This will work if your daemon correctly opens the log file in add mode. Most of them do it. (This command simply truncates the file size to zero and does not interfere with the process of adding another file to the file in append mode.)

- , syslog . Linux , ( ..) syslog.

+4

, fifo .

0

To trim a log file but save the last 1000 lines:

echo "$(tail -1000 daemonlog)" > daemonlog
0
source

Source: https://habr.com/ru/post/1750084/


All Articles