django - Crontab Jobs didn't execute shell script -
i'm developing django-python project , stuck in doing django-crontab automate file backup, code:
in settings.py
installed_apps = ( . . . 'django-crontab', ) crontab_django_manage_path = '/home/path/to/my/project/manage.py' cronjobs = [ ('25 15 * * *', 'cd /home/path/to/my/project && /usr/bin/sh myscript.sh'), ]
in myscript.sh
#!/bin/sh set -e cd /home/path/to/my/project/ exec cp file some_dir/copy_file
i test code on server run @ 15:25 o'clock , it's not executing myscript.sh
the script doing copy file directory (for up) , i've tested manually using ./myscript.sh in server, script working well...
i've been trying various methodology, nothing seems works
i take reference django-crontab (https://pypi.python.org/pypi/django-crontab/0.5.1) , site (https://superuser.com/questions/81262/how-to-execute-shell-script-via-crontab) + http://github.com/kraiz/django-crontab
edit
i've add cronjob using command
python manage.py crontab add
i've checked job there using command
python manage.py crontab show
working example
settings.py
cronjobs = [ # auto backup database everyday @ 4 ('0 4 * * *', 'django.core.management.call_command', ['dumpdata', 'myproject'], {'indent': 4, 'use_natural_keys': true}, '> /home/mydirectory/myproject_backup/myproject_backup.json'), ]
myproject_backup.json
[ { "pk": 1, "model": "contenttypes.contenttype", "fields": { "model": "permission", "name": "permission", "app_label": "auth" } }, { "pk": 2, "model": "contenttypes.contenttype", "fields": { "model": "group", "name": "group", "app_label": "auth" } }, { "pk": 3, "model": "contenttypes.contenttype", "fields": { "model": "user", "name": "user", "app_label": "auth" } }, { "pk": 4, "model": "contenttypes.contenttype", "fields": { "model": "contenttype", "name": "content type", "app_label": "contenttypes" } }, { "pk": 5, "model": "contenttypes.contenttype", "fields": { "model": "session", "name": "session", "app_label": "sessions" } }, { "pk": 6, "model": "contenttypes.contenttype", "fields": { "model": "site", "name": "site", "app_label": "sites" } }, { "pk": 7, "model": "contenttypes.contenttype", "fields": { "model": "logentry", "name": "log entry", "app_label": "admin" } }, { "pk": 8, "model": "contenttypes.contenttype", "fields": { "model": "poll", "name": "poll", "app_label": "polls" } }, { "pk": 9, "model": "contenttypes.contenttype", "fields": { "model": "choice", "name": "choice", "app_label": "polls" } }, { "pk": 10, "model": "contenttypes.contenttype", "fields": { "model": "cronjoblog", "name": "cron job log", "app_label": "django_cron" } }, { "pk": "1g6s3bly0gu6pn7spllerdw1n8sus08a", "model": "sessions.session", "fields": { "expire_date": "2013-09-04t05:48:32z", "session_data": "ytg4y2i3owm3nzg4nmiyoge2nmjizdaxymywmgniywi3zjg5ogfmmdqaan1xashvel9hdxrox3vzzxjfymfja2vuzhecvslkamfuz28uy29udhjpyi5hdxrolmjhy2tlbmrzlk1vzgvsqmfja2vuzhedvq1fyxv0af91c2vyx2lkcqskaqf1lg==" } }, { "pk": "j7ifcyfzfhentb5tx9492fphdf20g2qp", "model": "sessions.session", "fields": { "expire_date": "2013-09-11t04:54:37z", "session_data": "ytg4y2i3owm3nzg4nmiyoge2nmjizdaxymywmgniywi3zjg5ogfmmdqaan1xashvel9hdxrox3vzzxjfymfja2vuzhecvslkamfuz28uy29udhjpyi5hdxrolmjhy2tlbmrzlk1vzgvsqmfja2vuzhedvq1fyxv0af91c2vyx2lkcqskaqf1lg==" } }, { "pk": "m21on2le3kti3ezexzei1vpox57x8qgv", "model": "sessions.session", "fields": { "expire_date": "2013-09-05t06:29:00z", "session_data": "ytg4y2i3owm3nzg4nmiyoge2nmjizdaxymywmgniywi3zjg5ogfmmdqaan1xashvel9hdxrox3vzzxjfymfja2vuzhecvslkamfuz28uy29udhjpyi5hdxrolmjhy2tlbmrzlk1vzgvsqmfja2vuzhedvq1fyxv0af91c2vyx2lkcqskaqf1lg==" } }, { "pk": "x16t71c19o93kukwu5mvog1g76ynv3ip", "model": "sessions.session", "fields": { "expire_date": "2013-09-04t07:07:46z", "session_data": "ytg4y2i3owm3nzg4nmiyoge2nmjizdaxymywmgniywi3zjg5ogfmmdqaan1xashvel9hdxrox3vzzxjfymfja2vuzhecvslkamfuz28uy29udhjpyi5hdxrolmjhy2tlbmrzlk1vzgvsqmfja2vuzhedvq1fyxv0af91c2vyx2lkcqskaqf1lg==" } }, { "pk": 1, "model": "sites.site", "fields": { "domain": "example.com", "name": "example.com" } }, { "pk": 1, "model": "polls.poll", "fields": { "pub_date": "2013-08-21t05:56:00z", "question": "what doing?" } }, { "pk": 2, "model": "polls.poll", "fields": { "pub_date": "2013-08-21t05:58:00z", "question": "what's on mind?" } }, . . ]
if can help, appreciated :s
the cronjobs schedule in settings not added crontab until run python manage.py crontab add
.
Comments
Post a Comment