12

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 like this:

bash update.sh

I get following errors:

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

What is 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.

4
  • try to use: sudo bash update.sh lets see what will happen. Commented Sep 22, 2016 at 22:04
  • Are you executing the bash script the same way as manually running the php command? If you're running one of them through a web service or something the paths might be different. Commented Sep 22, 2016 at 22:04
  • 1
    wouldn't it be a carriage return end line problem? Can you do the following: dos2unix update.sh > newbatchfile and try the new one? (compare file sizes, if the newbatchfile is smaller: bingo) Commented Sep 22, 2016 at 22:06
  • Thanks @Jean-FrançoisFabre it works now ! Commented Sep 22, 2016 at 22:09

1 Answer 1

6

When a batch file passes through some windows-compliant editors or other mishaps, it may happen that carriage return chars are appended to the end of the line (just before linefeed)

so the all the lines for instance this one:

php /var/www/mysite/script1.php

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

Do the following:

dos2unix update.sh > newbatchfile.sh

or

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

(compare file sizes, if the newbatchfile is smaller, problem was CR chars and is fixed)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.