【问题标题】:Crontab python script does not run (with anaconda on linux server)Crontab python 脚本不运行(在 linux 服务器上使用 anaconda)
【发布时间】:2021-04-30 10:09:23
【问题描述】:

我有以下要完成的任务列表,它们正在成功运行。

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

analyzato​​r - 向电报发送消息的文件,这里是用于检查的设置

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

可能是什么问题,有些文件可以正常工作,有些则不能???

【问题讨论】:

  • 看来您需要在 cron 作业中设置 PATH 变量。
  • 您是否在 Windows 机器上创建了 shell 脚本?
  • @RamanSailopal 一切都已配置好,之前没有出现此类问题,旧设置成功。好像不是这样的
  • @tink 是的,我通过运行 Windows 10 的计算机 Moba 工作
  • 将文件转换为unix行尾...

标签: python linux bash cron


【解决方案1】:

您的 shell 脚本中遇到了 DOS 行尾,CR 被解释为文件名的一部分,而这确实不存在。

解决这个问题的一种方法是使用 linux 编辑器;另一种方法是使用

dos2unix < infile > outfile

【讨论】:

    猜你喜欢
    • 2017-04-27
    • 2014-10-06
    • 1970-01-01
    • 2021-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-21
    • 1970-01-01
    相关资源
    最近更新 更多