i've got some problem with rotating files. Situation is next:
- one program like wireshark or vlc dumps all to one file, say netstream.bin
- If i mv netstream.bin to netstream.bin.rotate program will still write to netstream.bin.rotate .
- As it is stream dump, this file would became larger and larger
Is there any solution, how to rotate this files?
Something like FILO pseudo file:
mkfilo /tmp/stream.buffer
./scrtip/program.bin -o /tmp/stream.buffer
get_out_filo(stream.buffer) > netstream.bin
My question also sounds like "How to change programs file descriptor to write another file"
A fifo may not work so nicely for you. There must be a reader on the other side, else the writer will block. Additionally once the reader is no longer reading the fifo the writer will exit with a broken pipe.
logrotate
can help you mostly, but it comes at the cost of possibly losing some data.The problem of losing data occurs between step 2 and 3. It is possible that more data gets written to the file after the file copy has copied what it thought was the end of the file. When step 3 occurs, you truncate (and lose) that data you missed during the copy.
Depending how much you need this, an alternative would be to write a program that is always reading from a fifo file, yet writes the data out to different places dependent on some condition (such as it receives a signal). This would be a clean way to do it but you'd need to write that program first!