5

I have following logrotate configuration file

/home/application/*/shared/log/*.log {
  daily
  rotate 10
  missingok
  nocompress
  notifempty
  copytruncate
  sharedscripts
  postrotate
    echo "Hi....." 
    /home/application/test.sh > /home/application/test_bash.log 2>&1
    echo "By....."
  endscript
}

/home/application/test.sh currently content is following (I try in shell script create dummy file too, but no success)

#!/bin/sh

echo "=============================================="

When I run logrotate all files are successfully rotated but test.sh script is not executed

Logrotate potput looks following:

running postrotate script running script with arg /home/application//shared/log/.log : " echo "Hi....." /home/application/test.sh > /home/application/test_bash.log 2>&1 echo "By....." "

/home/application/test_bash.log log file is not created.

I even try simple such example

/home/application/*/shared/log/*.log { 
  daily 
  rotate 10 
  missingok 
  nocompress 
  notifempty 
  copytruncate 
  sharedscripts 
  postrotate 
    mkdir /home/application/demo_v2/shared/log/arch 
  endscript 
}

Why logrotate is not executing my shell script? What I am doing incorrect?

user1124133
  • 169
  • 1
  • 3
  • 8
  • Please show us the full output of `logrotate -v -f /etc/logrotate.d/`? – quanta Jul 31 '12 at 16:35
  • 1
    Thanks you give me necessary hint. I was running lograte with **d** option `logrotate -dv -f /etc/logrotate.d/` Without **d** all was as expected – user1124133 Jul 31 '12 at 18:57
  • Is /home mounted with noexec? Is SELinux/Apparmor permitting execution of scripts in /home? Also, your mkdir example needs mkdir -p or it will fail if the directory exists. _Logrotate will see a fail status_ – Aaron Jan 01 '15 at 14:20

2 Answers2

1

As someone said previously the "echo" commands will fail, as logrotate has no TTY, so you might try...

echo "Hi....." > /home/application/test_bash.log
/home/application/test.sh >> /home/application/test_bash.log 2>&1
echo "By....." >> > /home/application/test_bash.log

It's unclear what logrotate might do if you attempt something like echo without a TTY.

The output from - logrotate -dvf - seems to indicate your script has run.

First try something simple like - echo foo > /home/application/test_bash.log 2>&1

If this works, then the script should be easy to debug.

David Favor
  • 171
  • 2
0

Logrotate does not have a magical TTY attached; where did you expect this output to be written to ?

One would normally run a script that redirects its output to a dedicate dlog, and avoid outputting anything on stdout; you seem to have confused several concepts above.

Perhaps, if we knew what it is you want to actually do with this logrotate script, somebody could help.

adaptr
  • 16,576
  • 23
  • 34
  • I even try following postrotate script. No success `/home/application/*/shared/log/*.log { daily rotate 10 missingok nocompress notifempty copytruncate sharedscripts postrotate mkdir /home/application/demo_v2/shared/log/arch endscript }` When I run: logrotate -dvf /etc/logrotate.d/application_log_conf I got Response: `running postrotate script running script with arg /home/application/*/shared/log/*.log : " /home/application/test.sh "` – user1124133 Jul 31 '12 at 14:32