PHP ssh2_exec,一次执行多个命令 [英] PHP ssh2_exec, executing multiple commands at once

查看:416
本文介绍了PHP ssh2_exec,一次执行多个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ssh2_exec在CentOS服务器上从PHP执行一些命令,并且已经使用了很多次,但是今天,当我尝试使用&&'使其一次执行4或5个命令时,它不工作.这是下面的代码:

I'm using ssh2_exec to execute a few commands from PHP on my CentOS servers, and I have used it many times, but today, when I tried making it do 4 or 5 commands at once with &&, it did not work. Here is the code below:

if (!($stream = ssh2_exec($con, 'cp -rf /home/shared/Tekkit_Server_3.1.2.zip /home/servers2/'.$mUsername.' && unzip /home/servers2/'.$mUsername.'/Tekkit_Server_3.1.2.zip && rm -rf /home/servers2/'.$mUsername.'/mods/mod_NetherOres.jar && mv -f /home/servers2/'.$mUsername.'/Tekkit.jar /home/servers2/'.$mUsername.'/craftbukkit.jar'))) {
    echo "fail: unable to execute command\n";
}

将ZIP文件复制到正确的目录中,但是从那里什么也没有,有什么想法吗?

It copy's the ZIP over to the right directory, but then does nothing from there, any ideas?

谢谢!

编辑

我只是尝试做:

 if (!($stream = ssh2_exec($con, 'unzip /home/servers2/'.$mUsername.'/Tekkit_Server_3.1.2.zip'))){
                        echo "fail: unable to execute command\n";
 }

它返回:失败:无法执行命令

and it returned: fail: unable to execute command

其他命令运行正常,当我在终端中运行该命令时运行正常.

Other commands work fine, and when I run the command in the terminal it works fine.

推荐答案

我测试了您的示例,如果您为unzip命令提供-d选项并指定了要解压缩文件的目录,则该示例似乎可以正常工作:

I tested your example and it looks like it works if you supply -d option to unzip command and specify the directory where the file should be unpacked:

if (!($stream = ssh2_exec($con, 'unzip /home/servers2/'.$mUsername.'/Tekkit_Server_3.1.2.zip -d /home/servers2/'.$mUsername))){
    echo "fail: unable to execute command\n";
}

这篇关于PHP ssh2_exec,一次执行多个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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