Note: This is a public test instance of Red Hat Bugzilla. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback at
Bug 5 - logrotate fails (unnecessarily) when prerotate script runs without effect
Summary: logrotate fails (unnecessarily) when prerotate script runs without effect
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: logrotate
Version: 5.2
Hardware: All
OS: Linux
Target Milestone: ---
Assignee: David Lawrence
QA Contact:
Depends On:
TreeView+ depends on / blocked
Reported: 1998-11-08 18:44 UTC by seth
Modified: 2013-05-06 17:15 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 1998-11-20 12:00:42 UTC
chaowan: needinfo-

Attachments (Terms of Use)

Description seth 1998-11-08 18:44:14 UTC
I am reasonably certain that I have found an undocumented
piece of behavior in the prerotate part of logrotate-2.6
In particular, commands have to succeed if logrotate will
succeed.  This makes it clumsy to use logrotate to,
for example, grep out potentially interesting pieces of
log files.

Let me illustrate.

Here is an example from the relevant part of the
config file.


grep something filename >> output


If grep does not find anything, then the following
error message is reported.  (I have just clipped out
a piece from the error message that was mailed to me,
of course the file name depends on what script is
being run, but I have confirmed this with different
logs and scripts).

errors occured while rotating /home/seth/adm/info.log

error running prerotate script --
                                leaving old log in place

However, if I add a test to check whether there
is anything to grep before trying to grep:

check=`/usr/bin/grep passwd /home/seth/adm/info.log `
if [ -n "$check" ] ; then
grep passwd /home/seth/adm/info.log >> output

Then it works all right.

I can reliably repeat this error.

Thanks for any feedback about the validity of this

Comment 1 zblaxell 1998-11-17 19:16:59 UTC
Two solutions:

	grep something filename >> output || exit 0

(i.e. grep succeeds, or 'exit 0' succeeds)


	grep something filename | cat >> output

(the pipeline will ignore the exit status of grep, but will still
report errors such as "no space left on device" or "permission denied"
or "I/O error").

Perhaps the documentation should be updated.  The principle of least
surprise says that the established behavior shouldn't change.

Comment 2 seth 1998-11-20 05:43:59 UTC
Ok...I looked in the source code.  I can see starting line 395

  if (runScript(log->files[logNum], log->pre)) {
                    fprintf(errorFile, "error running prerotate script
                                leaving old log in place\n");
                    hasErrors = 1;

And RunScript() is returning the result from the system command.
So presumably a grep that finds nothing is appearing to be an
error.   It has been a while since I have played with system()
Isn't it possible to have more nuance in interpreting the
kinds of errors?

If not, then perhaps the man page should be modified to reflect
this fact.

Comment 3 Preston Brown 1998-11-20 12:00:59 UTC
by de facto standard, unix commands exit with a nonzero status when
there has been an error.

Comment 4 seth 1998-11-20 14:23:59 UTC
> by de facto standard, unix commands exit with a nonzero status
  > when there has been an error.

True.  But you do not seem to appreciate the point that the
manpage logrotate(1) does not inform what logrotates behavior will be
under those circumstances.

Here is the relevant piece:

              The lines between prerotate and endscript (both  of
              which  must appear on lines by themselves) are exe-
              cuted before the log file is rotated. These  direc-
              tives  may only appear inside of a log file defini-
              tion.  See postrotate as well

Nowhere does it say "Failures will result in the non-execution of
the rotation" or warn that this also means that greps that return
nothing will count as a failure.

You can discard the issue if you want, but it is poor documentation,
especially when one considers the "typical" use of a prerotate
script would be pull out and save potentially interesting
things from a log file, and where one is likely to get a
grep that returns nothing.


Note You need to log in before you can comment on or make changes to this bug.