- Does the file end with an empty line? The crontab files must end with an empty line.
- Are the file permissions correct? The cron process might not be able to read the files. (Have atleast
chmod 644
)
- Example problem:
- I copied a file into the docker container inside the Dockerfile.
- I did an
sed -i
replace inside my entypoint (which causes the file to be newly created). - The cronjob was not executed.
- I fixed it by setting
chmod 600
after thesed -i
replace.
- Inside
crontab
and/etc/cron.d/
(system crontabs) the cron jobs must have a user specified, for example:* * * * * www-data <job>
. - Is cron running in the foreground (
cron -f
) when running inside a docker container? - When running in docker; use something like Supervisor to start it in the foreground. Otherwise it won't work.
- If you're using scripts (inside
/etc/cron.daily
for example), make sure that the filename is correct:Files must conform to the same naming convention as used by run-parts(8): they must consist solely of upper- and lower-case letters, digits, underscores, and hyphens.
. Also make sure the files are executable (chmod +x <file>
)! - You can not use environment variable in a cronjob line.
- Example:
* * * * * www-data echo "$SOME_VAR" >> /tmp/crontest
- A workaround to do something like this using Docker:
- Copy the file in the Dockerfile
- Using
sed
inside the entrypoint to replace the variable. Make sure to set the permissions to 600 (chmod 600
) afterwards!
- A workaround to do something like this using Docker:
- Does the application load environment variables dynamically? The crontab does not run in the same environment as the user! Possible solutions are to source the environment variables (for example using a shell script), or use a .env file for your application.
https://debian-administration.org/article/687/So_your_cronjob_did_not_run