需要使用 cpanel 通过 cron 作业运行 python 脚本
我在这方面需要紧急帮助。我正在尝试通过 cPanel 上的 cron 作业运行 Python 脚本。 Web 托管服务器正在使用 cPanel 版本 11.30.3(build 5)
。 cron 作业已成功设置并且正在执行该文件,但由于我在电子邮件中收到的以下错误,该文件失败了:
/bin/sh: /home/someuser/public_html/xml_feed/cron_job_wod.py: /usr/bin/python
: bad interpreter: No such file or directory
到目前为止我所做的事情:
- 我已将
cron_job_wod.py
放在 < code>public_html/xml_feed/cron_job_wod.py 具有所有权限 777 代码 - 我已在我的脚本顶部添加了此
#!/usr/bin/python
- 我已添加
appache handler
调用了cgi-script
,扩展名为.cgi .py .pl
...但脚本仍然无法工作。如何获得Python解释器的正确路径?或者这个问题的解决方案是什么?请帮忙!
I need urgent help in this regard. I am trying to run a Python script via cron job on cPanel. The web hosting server is using 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:
/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:
- I have placed
cron_job_wod.py
underpublic_html/xml_feed/cron_job_wod.py
with all permission 777 code - I have added this
#!/usr/bin/python
at top of my script - I have added
appache handler
calledcgi-script
with extensions.cgi .py .pl
...but still the script is not working. How could I get the right path of the Python interpreter? or what is the solution for this problem? Please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请注意,在错误消息中,
/usr/bin/python
之后和:
之前有一个换行符,用于澄清该消息。这表明操作系统不是在/usr/bin/python
而是在/usr/bin/python
处查找文件。最有可能的是,您从 Windows 系统复制了 python 文件,该文件具有
/bin/sh
不希望在脚本中看到的换行样式。您可以通过使用以下命令转换 python 脚本文件中的 Windows 样式换行符来解决此问题。
如果
dos2unix
在您的系统上不可用,这里列出了可实现相同更改的替代方法。Note that in the error message, there is a line break after
/usr/bin/python
and before the:
that clarifies the message. This suggests that the operating system is seeking the file not at/usr/bin/python
but at/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.You can solve this problem by converting the Windows-style newlines in the python script file with the following command.
If
dos2unix
is not available on your system, here are a list of alternative methods that effect the same change.