Relevant parts of Dockerfile:
RUN apt-get install -y cron
RUN service cron start
ADD cronjob /etc/cron.d/gptswmm-cron
RUN chmod 0644 /etc/cron.d/gptswmm-cron
RUN touch /var/log/cron.log
RUN crontab /etc/cron.d/gptswmm-cron
RUN cron
I check ps -ef
output and cron isn't there. Whatever, I can spin it up manually after the fact with cron
command and it shows up (just to check all my boxes, also do service cron start
).
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 15:54 pts/0 00:00:00 /bin/bash
root 41 0 0 15:59 ? 00:00:00 cron
root 65 0 0 16:02 ? 00:00:00 ps -ef
I do crontab -l
and get the same as in my cronfile (which does have the empty line and the end too):
MAILTO=""
* * * * * root python /var/test/testcron.py >> /var/log/cron.log 2>&1
Python file simply creates (or appends to, if existing) a test file in the same directory (ensured same dir as script location), repeating the same word. As simple a test as you can get. (I originally had it echo-ing to log file, but did this as I'm more comfortable with what's going on in a python script than bash). Python file is owned by root with all permissions to owner.
Yet when I check where the text file should be, nothing. When I check /var/log/cron.log
, it's empty.
When I manually call python /var/test/testcron.py
it works and creates the output file.
So I get some system logging going, redoing the Dockerfile with this at the end:
RUN apt-get install -y rsyslog
Rebuild and spin up container. Start rsyslog first rsyslogd
, then cron with cron
and double-checking with service start cron
.
Check /var/log/syslog
and cron seems to be getting called, these basic two lines repeat every minute:
... CRON[48]: (root) CMD (python /var/test/testcron.py >> /var/log/cron.log 2>&1^M)
... CRON[47]: (root) CMD (root python /var/test/testcron.py >> /var/log/cron.log 2>&1^M)
I'm at a loss here. Been googling and searching for various solutions, but nothing so far has worked.
/usr/bin/python
and w/o the2>&1
stuff. Not sure which did it (I'll test and figure out, but my guess is the 2nd thing). The^M
still gets appended at the end of the syslog, just looks like.../cron.log^M)
now. However, I'm seeing the output file now. I'll report back shortly whether pointing it to python absolutely or the2>&1
removal was what did it.