Run php in bash script: error "Could not open input file"

I made a simple script like:

#!/bin/bash php /var/www/mysite/script1.php php /var/www/mysite/script2.php 

When I run it as root as follows:

 bash update.sh 

I get the following errors:

 Could not open input file: /var/www/mysite/script1.php Could not open input file: /var/www/mysite/script2.php 

What's wrong? I tried with permissions 777 on my php files and all folders to access it. When I do directly php / var / www / mysite / script1.php in my command line, it works fine.

+7
bash php
source share
1 answer

When a batch file goes through some window-compatible editors or other failures, it may happen that carriage returns are added to the end of the line (just before the line)

so all lines, for example, are:

 php /var/www/mysite/script1.php 

contains an invisible \r char, which is interpreted as part of the py argument php => file /var/www/mysite/script1.php<invisible char> not found.

Follow these steps:

 dos2unix update.sh > newbatchfile.sh 

or

 tr -d "\015" < update.sh > newbatchfile.sh 

(compare file sizes, if newbatch file size is smaller, the problem was CR-characters and fixed)

+4
source share

All Articles