在FreeBSD中将python脚本作为cron作业运行

问题描述:

我是FreeBSD的新手。
我刚刚设置了服务器并安装了python 3.6。
现在我想每天15h00运行一个python脚本,因此我尝试设置cron任务。
但是在某种程度上,cron任务永远不会运行或给我错误。
由于cron使用邮件报告错误,并且服务器上似乎未安装邮件,因此我不知道脚本是实际运行还是根本不运行。
/ etc / crontab中添加的行如下:

I'm new to freeBSD. I just set up a server and installed python 3.6. Now i want to have a python script run every day at 15h00, so i tried to set up a cron task. But in some way, the cron task never runs or is giving me errors. Since cron uses mail to report errors and mail doesn't seem to be installed on my server, I have no clue whether the script actually runs or is not running at all. The line added in /etc/crontab is the following:

0 15 * * * root /usr/local/bin/python3.6 /root/myscript.py

其中/ usr / local / bin是安装python的目录。
在普通命令行中运行此命令时,它可以正常运行,但是使用cron时,它始终无法工作。
欢迎任何帮助

Where /usr/local/bin is the directory where python is installed. When running this command in the normal command line, it works perfectly, but with cron, it keeps not working. Any help is welcome

预先感谢

要调试环境,请将其添加到 / etc / crontab

To debug your environment add this to /etc/crontab

* * * * * root env > ~/cronenv

等待文件〜/ cronenv (在一分钟后创建)并使用环境启动新的shell:

Wait for file ~/cronenv to be created (after a minute) and start a new shell using does environments:

env - `cat ~/cronenv` /bin/sh

然后调用脚本 / usr / local / bin / python3.6 /root/myscript.py

这将有助于在同一环境中测试/调试代码 cron 正在使用。

This will help to test/debug your code within the same environment cron is using.