Executing PHP files from shell

fshagan

Verified User
Joined
Aug 2, 2011
Messages
38
Wondering what I'm doing wrong ... I have a script from CloudNS to copy DNS zones to slave name servers that starts with:

Code:
#!/usr/local/bin/php
<?php
// stuff here
?>

I'm getting the error:
-bash: ./directadmin-slave-zones-add.php: /usr/local/bin/php^M: bad interpreter: No such file or directory

/usr/local/bin/php does have a symlink to the PHP on my system, so I'm not sure what I'm doing wrong. Any help?

Server: CentOS 7
 
Hello,

It seems you're working from a windows based text editor which adds \r\n instead of single \n breaklines.

I would suggest that you open the file in a Linux editor or correct settings of your editor to use only \n as line-break.
 
If you want, you can convert the file

Code:
dos2unix filename.php
 
Thanks!

I am using Notepad++, but it was adding \r\n to each line. I'll have to find it in the settings. I removed the extra \r carriage return and got the script to work! It is syncing my DNS zones properly now.
 
Back
Top