1

I run sudo crontab -e and append the following line:

* * * * * logrotate -f /etc/logrotate.d/adraw; touch /ADraw/Data/Logs/test.txt

The file test.txt is successfully created, but I see no results of logrotate. Strangely, if I run sudo logrotate -f /etc/logrotate.d/adraw everything works (additional files created).

my /etc/logrotate.d/adraw configuration:

/ADraw/Data/Logs/*.log {
    hourly
    size 1M
    missingok
    rotate 5
    compress
    delaycompress
    notifempty
    create 0640 ADraw ADraw
    sharedscripts
    prerotate
        if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
            run-parts /etc/logrotate.d/httpd-prerotate; \
        fi \
    endscript
    postrotate
        invoke-rc.d nginx rotate >/dev/null 2>&1
    endscript
}
6
  • 2
    At least on my system, logrotate is in /usr/sbin - which is likely not in cron's default PATH. Please try again with the full path /usr/sbin/logrotate Apr 25 '20 at 23:37
  • Yes, this solves the problem. Thank you!
    – Apogentus
    Apr 25 '20 at 23:47
  • @steeldriver If you don't start posting your comments as answers I might catch up to you in points! Apogentus please accept your own answer in two days so it comes off the unanswered questions database listing. Apr 26 '20 at 0:04
  • @steeldriver The default path for cron is /usr/bin and /bin as stated this Q&A: Where is cron's PATH set? asked by the renowned Terdon and answered by the renowned muru. Apr 26 '20 at 0:20
  • @WinEunuuchs2Unix indeed - and as posted by me here Can't mount another server in crontab with 16.04 Apr 26 '20 at 0:29
2

As steeldriver said, the solution was to add full path to logrotate in cron:

* * * * * /usr/sbin/logrotate -f /etc/logrotate.d/adraw; touch /ADraw/Data/Logs/test.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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