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
  • 30,211
  • 62
  • 184
  • 246

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
  • 128,755
  • 40
  • 271
  • 413
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
  • 16,882
  • 2
  • 36
  • 66
  • 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. – Amandasaurus Nov 03 '11 at 09:51
  • @RoryMcCann As I wrote: With -f it does **not** log to syslog, but to a file. – mailq Nov 03 '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 – Amandasaurus Nov 03 '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. – Amandasaurus Nov 03 '11 at 14:47