I have the following crontab setup.
30 * * * 1-5 /home/ubuntu/script_abc.sh
script_abc.sh has permission -rwxr-xr-x and the following content.
#!/bin/sh
source ~/my_app/venv/bin/activate
export APP_KEY=abkajdfljdasfljdalfk
cd ~/my_app
python ~/my_app/scripts/scan.py
It seems crontab never run my script. Any idea?
2 Answers 2
crontab dosn't set PATH an cannot find the binarys. Add PATH at the top of your script, or with an export at top of crontab.
# for example
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
Comments
Is it a local user's crontab or are you making changes in /etc/cron.d/ if it is the latter, you need to mention the user name like I am doing in the below example:
30 14 * * * root <script>
if it is the former, you can.
Look at the syslog. You will see what is happening when the cron daemon tried to call your script.
Make sure you have absolute path in all your scripts.
~//usr/bin/python. You can get full path for program usingwhich- ie.which python.profileand.bashrcare skipped bycrontab, PATH modifications and other settings are ignored. Trysource /home/ubuntu/.profileinside your script or your crontab command.