Does there exist a command where one can do something like:
someprogram | tee --limit=1MB afile
Whereby "afile" would contain the most recent 1 MB of output of "someprogram"?
Does there exist a command where one can do something like:
someprogram | tee --limit=1MB afile
Whereby "afile" would contain the most recent 1 MB of output of "someprogram"?
Exactly that, probably not. Once it had warmed up and filled the file, it would be rewriting 1MiB-N bytes of old data, to shuffle them along the file, for every N bytes of new data that it added to the end of the buffer. This is not exactly an ideal mechanism, and moreover reading the file as it is being written would be prone to "tearing" problems.
Close to that, many commands exist. Raise the number of files to 2, a current file and its immediate predecessor, so that at any given time one has between 1MiB and 2MiB of the most recent output, with output not being copied around once it has been written; and you have something that a whole bunch of daemontools-family logging programs do by design. They are, in essence, exactly this sort of "tee plus".
multilog from daemontools and Bruce Guenter's multilog from daemontools-encore: someprogram | multilog n2 s1048576 ./logdir/
s6-log from s6: someprogram | s6-log n2 s1048576 ./logdir/
svlogd from runit with a configuration file that says n2 s1048576: someprogram | svlogd ./logdir/
tinylog from perp: someprogram | tinylog -k 1 -s 1048576 ./logdir/
cyclog from nosh: someprogram | cyclog --max-file-size 1048576 --max-total-size 1048576 ./logdir/
logrotate or newsyslog in this century.. Frequently Given Answers.In package apache2-utils is present utility called rotatelogs, it fully meet to your requirements.
Synopsis:
rotatelogs [ -l ] [ -L linkname ] [ -p program ] [ -f ] [ -t ] [ -v ] [ -e ] [ -c ] [ -n number-of-files ] logfile rotationtime|filesize(B|K|M|G) [ offset ]
Full manual you may read on this link.