Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wonder is there a programme that'll do what I want. This is like an streaming log rotation programme. For the linux/unix command line.

Let's say I have some input that is streaming some data. I want to write it a file, but a different file per day (or hour or whatever), i.e. open a file with a specified datetime based pattern, and write the contents of stdin to that file. when the day changes (or the hour or the minute, or the week etc), close that file, then re-open a new one (which will have a new filename), and write lines to that file instead?

So something like:

my long | process | that's generating | input | datestampfilewriter --daily 'output.%Y-%m-%d.txt'

Does this tool exist?

share|improve this question
up vote 5 down vote accepted

You could use cronolog.

cronolog is a simple filter program that reads log file entries from standard input and writes each entry to the output file specified by a filename template and the current date and time. When the expanded filename changes, the current file is closed and a new one opened.

share|improve this answer
Yes, that is exactly what I asked for! – Rory Nov 3 '11 at 10:02

How about logger? Logs to syslog, which is "datestampped" and can be logrotated.

And with the -f option logs to a file. See man logger.

share|improve this answer
Good suggestion, but I don't want to log to syslog, since that's for system logging, and this is just the output of a programme. I also don't want to pollute the output lines in the log file. – Rory Nov 3 '11 at 9:51
@RoryMcCann As I wrote: With -f it does not log to syslog, but to a file. – mailq Nov 3 '11 at 12:23
I tried using -f, and it doesn't change anything. The message still goes to /var/log/syslog, and the file I give as argument to -f remains empty – Rory Nov 3 '11 at 14:04
Further investigation shows that the -f option doesn't log to that file, but includes the contents of that file in the syslog. Which means logger isn't a solution. – Rory Nov 3 '11 at 14:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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