Use tee (or equivalent) but limit max file size or rotate to new file

前端 未结 7 1594
抹茶落季
抹茶落季 2020-12-05 02:24

I would like to capture output from a UNIX process but limit max file size and/or rotate to a new file.

I have seen logrotate, but it does not work real-time. As I

7条回答
  •  失恋的感觉
    2020-12-05 03:21

    use split:

    my_program | tee >(split -d -b 100000 -)
    

    Or if you don't want to see the output, you can directly pipe to split:

    my_program | split -d -b 100000 -
    

    As for the log rotation, there's no tool in coreutils that does it automatically. You could create a symlink and periodically update it using a bash command:

    while ((1)); do ln -fns target_log_name $(ls -t | head -1); sleep 1; done
    

提交回复
热议问题