我有一个bash脚本run.sh --- -rwxrwxr-x
(我做了chmod + x run.sh)
当我运行./run.sh
脚本时效果很好(将数据追加到文件中)
但是它在crontab中不起作用
crontab -l
表演 * * * * * ./run.sh
#!/bin/bash
export DJANGO_SETTINGS_MODULE=eda_parser.settings # eda_parser -- name of the project and the main app
cd /home/alex/root_folder/projects/5_eda_parser/eda_parser
source ../venv/bin/activate # run venv
python manage.py delete_old # main django command
eda_parser/
├── manage.py
├── eda_parser # main app
...
├── run.sh # script to run
├── scraper # django commands app
│ ...
│ ├── management
│ │ └── commands
│ │ ├── delete_old.py # code of the command
which python
以了解您的python可执行文件的路径,然后在您的shell脚本中使用此python可执行文件路径。#!/bin/bash
export DJANGO_SETTINGS_MODULE=eda_parser.settings # eda_parser -- name of the project and the main app
/home/sysadmin/.virtualenvs/virtual_environment/bin/python /absolute/path/of/your/manage.py delete_old # main django command
同样,在设置crontab时,您需要提供shell脚本的绝对路径。假设您希望它在处运行01:15
,并将其附加到中crontab -e
。
15 1 * * * /absolute/path/to/your/shell/script.sh
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句