1👍
Step 1: Add Shebang to script
Unix scripts use a line called “Shebang“
So your first line should look like this:
#!/usr/bin/env python
Stept 2: Make script executable
- Go to the folder with your script
mysript.py
- Execute
chmod +x myscript.py
in console. - Verify that it is executable by executing it with
./myscript.py
.
Step 3: Add it to CRON
- Type
crontab -e
in terminal. -
Add a line like this:
30 13 * * * /home/yourusername/myscript.py
-
Verify with
crontab -l
that everything worked.
(see cyberciti.biz for more information)
Debugging python scripts
import datetime
import getpass
now = datetime.datetime.now()
# Open file to append
with open("/home/user/myscript.log", "a") as f:
f.write("Script started at %i.%i.%i (%i:%i:%i) by %s" % (now.day, now.month, now.year, now.hour, now.minute, now.second, getpass.getuser()))
[...]
with open("/home/user/myscript.log", "a") as f:
f.write("File 'xy' was opened.")
0👍
check first your crontab is running. add a job to create a file in tmp folder. IF it is running. try to give full path for python like
* /usr/bin/python /home/path of your django project/manage.py …
0👍
In your terminal write crotab -e . There put your
* * * * * /usr/bin/python /Users/path_to_csv/test_subprocess.py
And in the test_subprocess.py add
DJANGO_SETTINGS_MODULE=project.settings
and also note that DJANGO_SETTINGS_MODULE=project.settings will only work if you run this cron job in project folder. So it would be better to use it as DJANGO_SETTINGS_MODULE=/pathToProject/project.settings
- [Answer]-URL Conf – Serving views at the root URL and non root URLs within one app
- [Answer]-Django: model.ForeignKey referring to field type
0👍
!/usr/bin/env python is fine
just set project setting full path to DJANGO_SETTINGS_MODULE
DJANGO_SETTINGS_MODULE=/Users/path_to_project/project.settings
-
-
-
-
- python /Users/path_to_csv/test_subprocess.py
-
-
-
- [Answer]-Where templates are widgets?
- [Answer]-Use form_class in base template in Django
- [Answer]-Django do I need to open port on ipv6 and ipv4?
- [Answer]-Nested for-cycles in Django templates
- [Answer]-Django only matches urls with an app prefix/identifier