使用anaconda env运行crontab作业 [英] run a crontab job using an anaconda env

查看:186
本文介绍了使用anaconda env运行crontab作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让cron作业使用一个已经存在的名为my_env的anaconda python环境执行python脚本.我唯一想做的就是让cron作业运行一个名为my_script.bash的脚本,然后依次激活env然后运行python脚本.

I want to have a cron job execute a python script using an already existing anaconda python environment called my_env. The only thing I can think to do is have the cron job run a script called my_script.bash which in turn activates the env and then runs the python script.

#!/bin/bash
source activate my_env
python ~/my_project/main.py

尝试从命令行执行此脚本不起作用:

Trying to execute this script from the command lines doesn't work:

$ sh scripts/my_script.bash
scripts/my_script.bash: 9: scripts/my_script.bash: source: not found

我需要怎么做才能确保激活正确的环境.可以像我5岁时向我解释一下.

What do I need to do to make sure the proper environment is activated. Its ok to explain it to me like I'm 5.

推荐答案

不要调用sh,而是bash. source是bash命令.

Don't call sh but bash. source is a bash command.

- sh scripts/my_script.bash
+ bash scripts/my_script.bash

或者只是

chmod +x scripts/my_script.bash
./scripts/my_script.bash

自从您添加了bash shebang.

since you added the bash shebang.

这篇关于使用anaconda env运行crontab作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆