[英]need to run python script via cron job using cpanel
I need urgent help in this regard. 在这方面,我需要紧急帮助。 I am trying to run a Python script via cron job on cPanel. 我正在尝试通过cPanel上的cron作业运行Python脚本。 The web hosting server is using cPanel Version 11.30.3 (build 5)
. 网络托管服务器正在使用cPanel Version 11.30.3 (build 5)
。 The cron job is set successfully and it is executing the file, but the file failed because of the following error which I recieved on email: cron作业已成功设置并且正在执行文件,但是由于以下在电子邮件中收到的错误而导致文件失败:
/bin/sh: /home/someuser/public_html/xml_feed/cron_job_wod.py: /usr/bin/python
: bad interpreter: No such file or directory
What I have done so far: 到目前为止我做了什么:
cron_job_wod.py
under public_html/xml_feed/cron_job_wod.py
with all permission 777 code 我已将cron_job_wod.py
放置在public_html/xml_feed/cron_job_wod.py
并具有所有权限777代码 #!/usr/bin/python
at top of my script 我在脚本顶部添加了此#!/usr/bin/python
appache handler
called cgi-script
with extensions .cgi .py .pl
我添加了名为cgi-script
的扩展名为.cgi .py .pl
appache handler
...but still the script is not working. ...但是脚本仍然无法正常工作。 How could I get the right path of the Python interpreter? 如何获得正确的Python解释器路径? or what is the solution for this problem? 或该问题的解决方案是什么? Please help! 请帮忙!
Note that in the error message, there is a line break after /usr/bin/python
and before the :
that clarifies the message. 需要注意的是在错误消息,则是后换行/usr/bin/python
和之前的:
即澄清该消息。 This suggests that the operating system is seeking the file not at /usr/bin/python
but at /usr/bin/python<newline>
. 这表明操作系统不是在/usr/bin/python
而是在/usr/bin/python<newline>
查找文件。
Most likely, you copied the python file from a Windows system which has a style of linebreaks that /bin/sh
is not expecting to see in your script. 您很可能是从Windows系统复制了python文件,该Windows文件具有/bin/sh
不会在脚本中看到的换行符样式。
You can solve this problem by converting the Windows-style newlines in the python script file with the following command. 您可以通过使用以下命令在python脚本文件中转换Windows样式的换行符来解决此问题。
dos2unix /home/someuser/public_html/xml_feed/cron_job_wod.py
If dos2unix
is not available on your system, here are a list of alternative methods that effect the same change. 如果dos2unix
在您的系统上不可用, 这是影响相同更改的替代方法的列表 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.