简体   繁体   English

Crontab python 脚本不运行(在 linux 服务器上使用 anaconda)

[英]Crontab python script does not run (with anaconda on linux server)

I have the following list of tasks to complete and they are working successfully.我有以下要完成的任务列表,它们正在成功运行。

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

The file structure is as follows:文件结构如下:

 #!/bin/bash
 source /home/user/anaconda3/bin/activate
 python /home/user/Code/agapov/GHR_Y00011280.py 
 conda deactivate

But then a problem arises, I added several new files for execution and they do not work.但是随后出现了一个问题,我添加了几个新文件以供执行,但它们不起作用。 Here is an example of the code for such a file这是此类文件的代码示例

 #!/bin/bash
 source /home/user/anaconda3/bin/activate
 python /home/user/Code/analyzator.py 
 conda deactivate

As you can see, it is completely similar, the python file itself starts and does its job perfectly, but something goes wrong with the crowns如您所见,它完全相似,python 文件本身启动并完美地完成了它的工作,但是表冠出了点问题

Cron logs: 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 - a file that sends a message to a telegram, here are its settings for checking analyzator - 向电报发送消息的文件,这里是用于检查的设置

*/5 * * * * bash /home/user/Code/start_analyzator.sh >> ~/cron.log 2>&1

What could be the problem, some files work fine and others don't???可能是什么问题,有些文件可以正常工作,而有些则不能???

You're suffering from DOS line-endings inside your shell script, the CR gets interpreted as part of the file name, which indeed does not exist.您在 shell 脚本中遇到了 DOS 行尾,CR 被解释为文件名的一部分,这确实不存在。

One way of dealing with this would be to use a linux editor;处理此问题的一种方法是使用 linux 编辑器; another way would be to use另一种方法是使用

dos2unix < infile > outfile

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM