[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to use logrotate postrotate *bash* script



Steffen Dettmer wrote:
> logrotate seems to execute "postrotate" scripts using /bin/sh and I
> found no way where to specify which script interpreter to use.
> Starting with a she-bang line seem to have no effect. Even if I
> manually run logrotate as root who has /bin/bash as login shell,
> /bin/sh is used.
> 
> How to make logrotate to use the correct interpreter for
> "postrotate" scripts?

"Correct" is in the eye of the beholder.  /bin/sh is the standard
shell and therefore it _is_ the "correct" shell.  But as documented
the postrotate snippet is a /bin/sh section.

Ralf Mardorf wrote:
> using
> 
> sh myscript
> dash myscript
> bash myscript

Those will work.  Don't forget that most shells have a -c option to
run a command.  Then it doesn't need to be a file.  Then it can search
for the command on PATH.

  postrotate
    bash -c "some command with args here found on PATH"
  endscript

Could even be inline scripting as long as the quoting is correct.

  postrotate
    bash -c "if $foo; then bar; fi"
  endscript

But for the most part I recommend just using the standard shell.  It
will then work across many revisions of the system.  Bash itself has
had a lot of changes in recent history.  IMNHO it isn't worth the
effort to chase it.

What feature are you trying for that is worth the hassle?

Bob

Attachment: signature.asc
Description: Digital signature


Reply to: