Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

From the logrotate man page:

 prerotate/endscript
          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
          handling.

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

/var/log/vnc.log 
{
  rotate 6
  monthly
  compress
  missingok
  prerotate
      cat /var/log/vnc.log >> /archive/logs/vnc.log
  endscript
}
share|improve this answer
    
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. –  Sebastiaan Oct 22 '13 at 18:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.