Crontab python 脚本没有 运行(在 linux 服务器上使用 anaconda)
Crontab python script does not run (with anaconda on linux server)
我有以下任务列表要完成并且它们正在成功运行。
0 0 */1 * * bash /home/user/Code/agapov/start_GHR_Y00011285.sh >> ~/cron.log 2>&1
5 0 */1 * * bash /home/user/Code/agapov/start_GHR_Y00011280.sh >> ~/cron.log 2>&1
10 0 */1 * * bash /home/user/Code/agapov/start_GHR_Y10001320.sh >> ~/cron.log 2>&1
20 0 */1 * * bash /home/user/Code/agapov/aggregation.sh >> ~/cron.log 2>&1
25 0 */1 * * bash /home/user/Code/ivanov/start_API_N00001010.sh >> ~/cron.log 2>&1
文件结构如下:
#!/bin/bash
source /home/user/anaconda3/bin/activate
python /home/user/Code/agapov/GHR_Y00011280.py
conda deactivate
但是后来问题出现了,我添加了几个新的文件来执行,它们都不起作用。这是此类文件的代码示例
#!/bin/bash
source /home/user/anaconda3/bin/activate
python /home/user/Code/analyzator.py
conda deactivate
如您所见,它完全相似,python 文件本身启动并完美地完成了它的工作,但皇冠出现了问题
Cron 日志:
/home/user/Code/start_analyzator.sh: line 4: conda: command not found
/home/user/Code/start_analyzator.sh: line 2: /home/user/anaconda3/bin/activate
: No such file or directory
/home/user/Code/start_analyzator.sh: line 3: python: command not found
bash: /home/user/Code/ivanov/start_DS_N00001400.sh: No such file or directory
/home/user/Code/start_analyzator.sh: line 4: conda: command not found
/home/user/Code/start_analyzator.sh: line 2: /home/user/anaconda3/bin/activate
: No such file or directory
/home/user/Code/start_analyzator.sh: line 3: python: command not found
/home/user/Code/start_analyzator.sh: line 4: conda: command not found
analyzator - 一个将消息发送到电报的文件,这里是它的检查设置
*/5 * * * * bash /home/user/Code/start_analyzator.sh >> ~/cron.log 2>&1
可能是什么问题,有些文件可以正常工作,有些则不能???
您的 shell 脚本中存在 DOS 行尾问题,CR 被解释为文件名的一部分,而这实际上并不存在。
处理这个问题的一种方法是使用 linux 编辑器;另一种方法是使用
dos2unix < infile > outfile
我有以下任务列表要完成并且它们正在成功运行。
0 0 */1 * * bash /home/user/Code/agapov/start_GHR_Y00011285.sh >> ~/cron.log 2>&1
5 0 */1 * * bash /home/user/Code/agapov/start_GHR_Y00011280.sh >> ~/cron.log 2>&1
10 0 */1 * * bash /home/user/Code/agapov/start_GHR_Y10001320.sh >> ~/cron.log 2>&1
20 0 */1 * * bash /home/user/Code/agapov/aggregation.sh >> ~/cron.log 2>&1
25 0 */1 * * bash /home/user/Code/ivanov/start_API_N00001010.sh >> ~/cron.log 2>&1
文件结构如下:
#!/bin/bash
source /home/user/anaconda3/bin/activate
python /home/user/Code/agapov/GHR_Y00011280.py
conda deactivate
但是后来问题出现了,我添加了几个新的文件来执行,它们都不起作用。这是此类文件的代码示例
#!/bin/bash
source /home/user/anaconda3/bin/activate
python /home/user/Code/analyzator.py
conda deactivate
如您所见,它完全相似,python 文件本身启动并完美地完成了它的工作,但皇冠出现了问题
Cron 日志:
/home/user/Code/start_analyzator.sh: line 4: conda: command not found
/home/user/Code/start_analyzator.sh: line 2: /home/user/anaconda3/bin/activate
: No such file or directory
/home/user/Code/start_analyzator.sh: line 3: python: command not found
bash: /home/user/Code/ivanov/start_DS_N00001400.sh: No such file or directory
/home/user/Code/start_analyzator.sh: line 4: conda: command not found
/home/user/Code/start_analyzator.sh: line 2: /home/user/anaconda3/bin/activate
: No such file or directory
/home/user/Code/start_analyzator.sh: line 3: python: command not found
/home/user/Code/start_analyzator.sh: line 4: conda: command not found
analyzator - 一个将消息发送到电报的文件,这里是它的检查设置
*/5 * * * * bash /home/user/Code/start_analyzator.sh >> ~/cron.log 2>&1
可能是什么问题,有些文件可以正常工作,有些则不能???
您的 shell 脚本中存在 DOS 行尾问题,CR 被解释为文件名的一部分,而这实际上并不存在。
处理这个问题的一种方法是使用 linux 编辑器;另一种方法是使用
dos2unix < infile > outfile