Jump to content

ssh2_exec output ok, but command does not execute


Amired

Recommended Posts

Hi,

I'm trying to execute a process via PHP (ssh2).

Here's the code:

 

        $connection = ssh2_connect(**,22);
$stream = ssh2_auth_password($connection, $on_ssh, $on_pass);
$command = ssh2_exec($connection, "cd hlds");
$command = ssh2_exec($connection, "sh server_run &");

 

Everything here seems ok, $connection is good, and 'server_run' has chmod 777.

Actually if I login manually via PuTTy and do the exact same actions it works.

Why doesn't it now?

 

Thanks!

ssh2_exec() opens a new shell for each command...so in essence, the cd hlds never happend. can you do it like this:

   $connection = ssh2_connect(**,22);
   $stream = ssh2_auth_password($connection, $on_ssh, $on_pass);
   $command = ssh2_exec($connection, "sh hlds/server_run &");

ah...a poorly designed script...do this...create a file in your home dir called 'start_server.sh' and put this in it:

 

#!/bin/sh
cd hlds
sh hlds/server_run > /dev/null &

 

then for your PHP script:

   $connection = ssh2_connect(**,22);
   $stream = ssh2_auth_password($connection, $on_ssh, $on_pass);
   $command = ssh2_exec($connection, "./start_server.sh &");

This is the line that is generated when I manually activate the server:

[s_API FAIL] SteamAPI_Init() failed; unable to update local steamclient. Continuing with current version anyway.

 

And exactly instead of it the PHP put out the error. he cant make it to this line.

 

the error itself is not important it's something like "there was an error. server restart in 10 seconds"..

 

 

  • 9 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.