Is it possible with logrotate to take the content of a log and add it to an existing file?

Like so:
1. Put the content of /var/log/vnc.log after the content of /archive/logs/vnc.log
2. Truncate /var/log/vnc.log

In bash it would go like:
1. cat /var/log/vnc.log >> /archive/logs/vnc.log
2. echo > /var/log/vnc.log

I think it's not possible. What would be a logic way then? The above commands in a cronjob? Or is this setup too dirty?

1 Answer 1


From the logrotate man page:

          The  lines  between  prerotate and endscript (both of which must
          appear on lines by  themselves)  are  executed  (using  /bin/sh)
          before the log file is rotated and only if the log will actually
          be rotated. These directives may only appear inside a  log  file
          definition.  Normally,  the  absolute  path  to  the log file is
          passed as first argument to the script.   If   sharedscripts  is
          specified,  whole  pattern  is  passed  to the script.  See also
          postrotate.  See sharedscripts  and  nosharedscripts  for  error

So, you should add an entry like this in logrotate.conf:

  rotate 6
      cat /var/log/vnc.log >> /archive/logs/vnc.log
  • I've thought about it, and that indeed is the best option. Is the use of cat not dirty? Once I read that all the content is buffered in memory or something like that.
    – Sat
    Oct 22, 2013 at 18:38

You must log in to answer this question.

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