Running a python script as a cron job in FreeBSD

点点圈 提交于 2019-12-17 21:37:13

问题


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

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

Thanks in advance


回答1:


To debug your environment add this to /etc/crontab

* * * * * root env > ~/cronenv

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

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

Then call your script /usr/local/bin/python3.6 /root/myscript.py

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



来源:https://stackoverflow.com/questions/49284717/running-a-python-script-as-a-cron-job-in-freebsd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!