Reputation: 139
I'm trying to schedule a script with cron in kubuntu. If I execute the script manually line by line, it goes just fine, but scheduled with cron it raises the following SyntaxError:
File "/opt/django/myproject/myapp/cron/test.sh", line 4
python manage.py mycustomcommand
^
SyntaxError: invalid syntax
The content of the script test.sh is as following:
#!/bin/bash
source /opt/virtualenvs/myvirtualenv/bin/activate
cd /opt/django/myproject
python manage.py mycustomcommand
Basically the script activates a virtual enviroment where django is installed, then accesses to my project path, and then executes a custom django command. As said, this works fine if I do it manually.
I tried to schedule the script in cron with normal and root permissions also ("crontab -e" and "sudo crontab -e")
Any idea? Thanks!
Upvotes: 0
Views: 722
Reputation: 56477
The error suggests that you fire the command python manage.py mycustomcommand
from within the Python interpreter (and not as a bash command).
You probably have something like
1 * * * * python /path/to/myscript/test.sh
in your crontab entry which is a mistake and it should be
1 * * * * /path/to/myscript/test.sh
instead.
Upvotes: 4