在FreeBSD中将python脚本作为cron作业运行 [英] Running a python script as a cron job in FreeBSD

查看:166
本文介绍了在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.

这篇关于在FreeBSD中将python脚本作为cron作业运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆