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?

2 Answers 2

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.

1
  • Yes, that is exactly what I asked for! Nov 3, 2011 at 10:02
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.

4
  • 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. Nov 3, 2011 at 9:51
  • @RoryMcCann As I wrote: With -f it does not log to syslog, but to a file.
    – mailq
    Nov 3, 2011 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 Nov 3, 2011 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. Nov 3, 2011 at 14:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .