logrotate is not executing custom shell script in postrotate

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?


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.