3

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?

Amandasaurus
  • 33,461

2 Answers2

5

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.

Zoredache
  • 133,737
2

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.

mailq
  • 17,251