Is there any way to keep file size of log file fixed without rotating it by a new empty file and deleting (or archiving) the old file. For example, if I set log file maximum size to 1MB, after the file size increase beyond that limit it will be automatically clamped, the text is added on 'tail' and the oldest part of text is poped out to keep the file size 1MB.
You could write a little bash script to do this. Just tail the file to a certain byte count using
Your only solution may be to write your own userspace file system or contribute to an existing one. Look at the partial list at Filesystem in Userspace
If you don't have the skills to contribute, offer a project publicity or $$$ or both, to add it for you.
I wish I had the time to do it, I have always wanted something exactly like this.
You can do something similar using a FIFO, which is sort of like a zero-byte sized file.
However, note that if nothing is READING from this file, then the syslog process may become blocked, and will stop writing to ALL of your logfiles. I'm not sure if this behavior has been changed with newer versions of Ubuntu/CentOS.
One example here
For another example, try something like this.
Make your FIFO:
And add this to (r)syslog.conf, then restart syslog:
Then view the FIFO from one window:
And in another window, send some stuff to syslog:
You should see the "Test*" lines in the output of
This feature can be great for debugging, especially if you don't care to keep the data around for longer. For example, if you only want to see everything except for thefirewall spam, you can do something like this:
Here's my second answer. This is a pretty hackish.
Use watch(1) to repeatedly execute
And then view the file with:
The difference between
And well, I guess you could put a
* prune - clips off the tops of a list of files described in the * file /etc/default/prune. Designed to be run periodically * from cron, the idea is to automatically shorten log * files that grow forever. This file contains a list of * files (full pathname), and the number of blocks that * should be retained. To retain some sanity, prune will * clip the file after the next newline. The file * /etc/default/prune should look something like: * * /usr/adm/aculog 10 * /usr/adm/leo.log 5 * /usr/adm/messages 200 * /usr/adm/sup_log 5 * * The crontab entry on infoswx for prune looks like: * * 0 5 * * * /etc/prune >/usr/adm/prune.log 2>&1 * * Compile with: cc -O -o prune prune.c * * The following defines may be adjusted to suit your taste * and your system block size. * * Ray Davis infoswx!bees 09/25/85
Many (most? all?) daemons will re-open their log files if sent a HUP signal (e.g. by same cron job that runs prune)