Home > Backend Development > PHP Tutorial > php exec运行linux命令不成功有关问题!求大家帮忙

php exec运行linux命令不成功有关问题!求大家帮忙

WBOY
Release: 2016-06-13 13:36:55
Original
1335 people have browsed it

php exec运行linux命令不成功问题!求大家帮忙!
环境:ubuntu server  
情景:使用web页面来修改samba的用户密码

详细描述: 例如 这句:

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->exec("echo -e \"0\\n0\\n\"|sudo smbpasswd -as test3");
Copy after login

当我在 php页面中运行是 出现如下报错:

Mismatch - password unchanged.
Unable to get new password.

意思就是说,没有修改成功

但是 当我把里边的命令拿出来 放在系统命令行中运行,则会成功 !
下面是直接在命令行中运行的命令,nobody是我的apapche 用户,下面就是以apache用户来运行这条命令
PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--> sudo -u nobody echo -e "0\n0\n"|sudo smbpasswd -as test3
Copy after login


请大家看看 这是什么一个原因呢 ?

------解决方案--------------------
权限问题么?
用sudo权限执行你的php文件呢?

------解决方案--------------------
exec("echo -e \"0\\n0\\n\"|sudo smbpasswd -as test3");

双引号嵌套错误了,不是必须shell文件然后调用

exec('echo -e \"0\\n0\\n\"|sudo smbpasswd -as test3');
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template