Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cron作业未运行python_Cron_Windows Subsystem For Linux - Fatal编程技术网

Cron作业未运行python

Cron作业未运行python,cron,windows-subsystem-for-linux,Cron,Windows Subsystem For Linux,我试图让cron运行一个python文件,但它似乎没有运行。cron中的命令是: 24 21 * * * python /mnt/c/Users/saifl/git/StaffTrainingLog/automate.py 日志中出现了以下内容: Feb 16 21:24:01 MSI CRON[3839]: (slatifi) CMD (python /mnt/c/Users/saifl/git/StaffTrainingLog/automate.py) 但是,它实际上并不运行代码。当我在

我试图让cron运行一个python文件,但它似乎没有运行。cron中的命令是:

24 21 * * * python /mnt/c/Users/saifl/git/StaffTrainingLog/automate.py
日志中出现了以下内容:

Feb 16 21:24:01 MSI CRON[3839]: (slatifi) CMD (python /mnt/c/Users/saifl/git/StaffTrainingLog/automate.py)
但是,它实际上并不运行代码。当我在上面的backets中运行该命令时,它不会出现任何问题。请告知

更新(罗密欧回应后):

现在,我已将命令移动到脚本(自动执行脚本):

我现在在Crontab中有以下内容:

50 14 * * * /mnt/c/Users/saifl/git/StaffTrainingLog/automate_script

当在命令行中运行
/mnt/c/Users/saifl/git/StaffTrainingLog/automatic_script时,它可以工作,但是,它确实使用cron运行,正如它在日志中显示的那样,但什么也没有发生。

有趣的是。。。您的cron设置正确并且正在工作。问题可能在于您的脚本。 也许你忘了添加exec权限了?
尝试运行
chmod+x path/to/your/script
,然后再次运行cron。

执行这样的脚本时,几乎没有什么事情要做。最好为此创建专用脚本

#!/bin/bash
source ~/.bashrc
cd /mnt/c/Users/saifl/git/StaffTrainingLog
/path/to/python  automate.py
  • 获取
    .bashrc
    以获取您的环境设置
  • cd到脚本所在的目录
  • 使用python的绝对路径运行它
  • 并在cron中运行上述脚本

    24 21 * * * /path/to/the/script
    

    别忘了让脚本可执行

    这不是问题,因为我可以在控制台中运行python/mnt/c/Users/saifl/git/StaffTrainingLog/automation.py,它会工作的谢谢-脚本应该是什么扩展名?我尝试在没有文件扩展名的情况下执行上述操作,但日志中显示了以下内容,但仍然没有发生任何事情:2月17日14:17:01 MSICRON[4235]:(slatifi)CMD(/mnt/c/Users/saifl/git/StaffTrainingLog/automation_script)Feb 17 14:17:01 MSI CRON[4234]:(root)CMD(cd/&运行部件--报告/etc/CRON.hourly)
    24 21 * * * /path/to/the/script