通常我通过SSH进入我的EC2实例并运行:
Usually I SSH into my EC2 instance and run:
source MYVENV / bin / activate
我如何设置cronjob激活虚拟环境?我的Django脚本需要存储在〜/ .bash_profile
How do I set my cronjob to activate the virtual environment? My Django script requires ENVIRONMENT variables that are stores in ~/.bash_profile
我尝试按照此处的步骤无效
I tried following the steps here to no avail
Cron和virtualenv
SHELL=/bin/bash */1 * * * * root source /home/ec2-user/MYVENV/activate && python /home/script.py这是我目前在上面的设置。
This is my current setup above.
我在日志中得到以下错误:
I get this following error in the log:
/ bin / bash:root:找不到命令
/bin/bash: root: command not found
推荐答案创建一个shell脚本,例如scripts.sh
create a shell script eg scripts.sh
#!/bin/bash source /home/user/MYVENV/bin/activate python /path/to/file/script.py然后放入cron
*/1 * * * * bash /path/to/shell/script/scripts.sh脚本将加载您所有的环境变量并从您环境中的python执行
The script will load all your environment variables and execute from the python in your environment
更多推荐
如何在python虚拟环境中运行cronjob?
发布评论