Question

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

Was it helpful?

Solution

The usual trick is:

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

That would work provided that your daemon properly open the log file in append mode. Most of them do. (That command simply truncates file size to zero and that doesn't intervene with another process writing to the file in append mode.)

Another option is to check whether your daemon support syslog and activate it. Most Linuxes now are shipped with some log collector which automatically (based on rules, etc) archive syslog files.

OTHER TIPS

If the filename is constant, you can try creating a fifo in place of the log file and read from it into as many separate log iles as you want.

To trim the log file but to keep the last 1000 lines of it:

echo "$(tail -1000 daemonlog)" > daemonlog
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top