Jump to content

ssh2_exec output ok, but command does not execute


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...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.