banner
李大仁博客

李大仁博客

天地虽大,但有一念向善,心存良知,虽凡夫俗子,皆可为圣贤。

Crontab定时任务使用virtualenv/conda问题

Crontab 定时任务使用 virtualenv/conda 会出现无法激活环境 需要使用特殊参数

"$@"

来传递命令的后续参数

手动编写一个 wrapper.sh,包含如下内容

#! /bin/bash
cd /some/work/dir
source /some/virtualenv/dir/bin/activate
"$@"

测试使用

#bash
/some/work/dir/wrapper.sh python xxx.py

#crontab
*/5 8-20 * * * /some/work/dir/wrapper.sh python xxx.py

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.