Domanda

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";
}

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

Thanks!

EDIT

I tried doing just:

 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.

È stato utile?

Soluzione

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";
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top