Debugging cron on Docker

I had the issue of cronjobs not working (correctly) on my Docker instances.

This is what I did to fix it:

  1. Set correct permissions: chmod 0600 /etc/cron.d/cronjob
  2. Set correct owner: chown root /etc/cron.d/cronjob

When it failed, I could not find the logs of why it failed.
In order to see the output of the failed cronjobs, I installed postfix (because the output of cronjobs is being mailed) and I installed rsyslog

  1. Install postfix:
    apt-get update; apt-get install -y postfix; mkfifo /var/spool/postfix/public/pickup; service postfix restart
  2. Install rsyslog:
    apt-get update; apt-get install -y rsyslog; rsyslogd &

Now, whenever a cronjob failed, I could find output in either two locations:

  1. In the syslog: /var/log/syslog
  2. In the mail sent to root: /var/mail/root

Click Here to Leave a Comment Below

Leave a Reply: