在bash脚本中运行php:错误“无法打开输入文件"; [英] Run php in a bash script: error "Could not open input file"

查看:114
本文介绍了在bash脚本中运行php:错误“无法打开输入文件";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个简单的脚本,例如:

I made a simple script like:

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

当我以root身份运行时:

When I run it as root like this:

bash update.sh

我收到以下错误:

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

怎么了?我尝试对我的php文件和所有文件夹使用权限777进行访问.当我在命令行中直接执行php/var/www/mysite/script1.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.

推荐答案

当批处理文件通过某些与Windows兼容的编辑器或其他不幸事件时,可能会将回车符添加到该行的末尾(正好在换行符)

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

包含一个不可见的\r字符,该字符被解释为参数py php =>文件/var/www/mysite/script1.php<invisible char>的一部分.

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.

执行以下操作:

dos2unix update.sh > newbatchfile.sh

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

(比较文件大小,如果newbatchfile较小,则问题是CR字符并已解决)

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

这篇关于在bash脚本中运行php:错误“无法打开输入文件";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆