This is my shell script which i want to schedule using cron job.
parser.sh
#!/bin/bash
source .profile
workon venv
cd /home/ashish/deployments/myproject
export DJANGO_SETTINGS_MODULE=myproject.settings_production
python /home/ashish/deployments/myproject/myproject/manage.py parse_data
Cron job-
*/15 * * * * . /home/ashish/parser.sh
Whenever this cron job runs i receive a mail with errors:
/bin/sh: 6: /home/ashish/parser.sh: source: not found
/bin/sh: 7: /home/ashish/parser.sh: workon: not found
Traceback (most recent call last):
File "/home/ashish/deployments/myproject/myproject/manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
When i run this script from terminal –
. parser.sh #this gives no error
sh parser.sh #this gives errors
/bin/sh: 6: /home/ashish/parser.sh: source: not found
/bin/sh: 7: /home/ashish/parser.sh: workon: not found
What can be the possible error in this script ?
Best Answer
cron
usessh
, notbash
, so when you source the script (that's what the.
does), it is run undersh
, notbash
. Remove the.
.Also, the
PATH
for cron is limited. Specify the full paths to commands you use, such asworkon
, or setPATH
yourself.