I have configured crontab to have the following entry:
*/2 * * * * source /home/ubuntu/cronenv/python2.7/bin/activate && python /home/ubuntu/trial.py >> /var/log/mycron/trial.log 2>&1 && deactivate
By tailing the /var/log/syslog file, I can verify that the cron runs every two minutes. This is the entry in /var/log/syslog every two minutes
Nov 8 10:52:01 ip-172-31-0-41 CRON[2023]: (ubuntu) CMD (source /home/ubuntu/cronenv/python2.7/bin/activate && python /home/ubuntu/trial.py >> /var/log/mycron/trial.log 2>&1 && deactivate)
By running the command in terminal, it runs as intended and creates trial.log file in /var/log/mycron/
The folder has all the required permissions as shown below:
drwxrwxrwx 2 root root 4096 Nov 8 11:02 mycron
Please help me in figuring out the issue.
PATH
in your cron. You either set thePATH
env var correctly or use the absolute path topython
source
is failing, so&&
short circuits. Try redirecting stderr/out to a file from the firstsource
. You should see the error. (aside, this is one of the nice things about using systemd timers instead of cron, debugging is way easier)/bin/sh
isdash
- which doesn't support thesource
synonym for.