Closed nverhoye closed 2 years ago
Hi @nverhoye,
Environments differs between shell and crontab, you can check it with printenv
in shell / crontab
I use approach 2
Try something like this:
* * * * * application . ~/.profile; /usr/local/bin/php /app/foo.php
we should implement go-crond to get rid of the environment issue :)
Hi @kyrilg
Thanks for your reply, but it still does not work unfortunately.
I pushed
* * * * * application . ~/.profile; /usr/local/bin/php /app/foo.php
Instead of
# m h dom mon dow user command
* * * * * php /app/foo.php
No result :(
please make sure you have an empty line at the end (cron requirement).. otherwise your crontab is ignored, also make sure the permissions are correct and not world writeable.
go-crond will fix this with correct error messages.
Hi @mblaschke, i have an empty line at the end (cron requirement), also permissions are correct (0644).
Below crontab used now :
* * * * * application . /home/application/.profile; /bin/bash /app/scheduler_cron.sh --mode always >> /app/cron.log 2>&1
# An empty line is required at the end of this file for a valid cron file.
NOW file is executed, but file can't do works asked. I have message returned : "Could not find a binary for php"
This is content of scheduler_cron.sh :
#!/bin/bash
# Generate an error if any variable doesn't exist
set -o nounset
# Location of the php binary
PHP_BIN=$(which php || true)
if [ -z "${PHP_BIN}" ]; then
echo "Could not find a binary for php" 1>&2
exit 1
fi
In cron task "which php" return empty BUT when i'm connected to docker's container it return '/usr/local/bin/php'
See :
docker exec -it app bash
root@03dc0dd62e77:/$ su application
application@03dc0dd62e77:/$ which php
/usr/local/bin/php
Any ideas ? Thanks
The environment parameters are not passed to cronjobs. They are filtered by default and AFAIK there is no way to fix this other then replacing the cron daemon.
I will replace cron with gocrond this weeks to get rid of this stupid issue
Hi @mblaschke, can you share the solution ? Thanks
Hey, I just created an example of how to use crontab with webdevops docker-compose, you can check it our here: https://github.com/abagayev/docker-bootstrap-collection/tree/master/crontab-in-container
Hi, i'm trying to configure a task in crontab
File : /etc/cron/crontab
File is correctly copyed when i launch docker-compose, see :
But it not works. Also when i laugh manually /app/foo.php it works.
Info : foo.php is a file which write content on another file (log)
Where is the problem please ? Sorry for my bad english. Thanks.