0

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.

4
  • See if this helps: php.net/manual/en/function.ssh2-exec.php#59324 Commented Nov 14, 2012 at 21:33
  • Didn't seem to work using that method. I even just now tried separating them into separate commands with a sleep(5); in between each and it didn't work. Commented Nov 14, 2012 at 21:47
  • Can you have it output the results to a log on the target machine and then go look to see where it failed? Commented Nov 14, 2012 at 22:00
  • It's deffinatly failing with the unzip, but no error, for now I have just unzip the file on the server and I am copying that over, but only a temp fix I guess. Commented Nov 14, 2012 at 22:53

1 Answer 1

1

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