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!

Link to comment
Share on other sites

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 &");

Link to comment
Share on other sites

Hi, Thanks for the reply :)

I've tried it manually,

 

[1@localhost ~]$ sh hlds/server_run &
[1] 11653
[1@localhost ~]$ hlds/server_run: line 1: ./hlds_run: No such file or directory

 

How can I overcome that?

 

 

thanks

Link to comment
Share on other sites

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 &");

Link to comment
Share on other sites

Hey it's not my folder, it's a HL dedicated server >_< I'm just making the PHP.

I'll try it now.

 

Edit: Nope, still not working. I tried to make a "try" file and put a simple "wget" in it, and it worked. I don't know why this doesn't.

Link to comment
Share on other sites

The log was really helpful. It actually showed that the file actually runs, and there is an inside error which makes him crash.

The only thing is that when I manually login to PuTTy and do the exact same thing it works fine.

What the hell?

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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