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.pyunderpublic_html/xml_feed/cron_job_wod.pywith all permission 777 code - I have added this
#!/usr/bin/pythonat top of my script - I have added
appache handlercalledcgi-scriptwith 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!
Note that in the error message, there is a line break after
/usr/bin/pythonand before the:that clarifies the message. This suggests that the operating system is seeking the file not at/usr/bin/pythonbut at/usr/bin/python<newline>.Most likely, you copied the python file from a Windows system which has a style of linebreaks that
/bin/shis 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
dos2unixis not available on your system, here are a list of alternative methods that effect the same change.