SA-MP Forums Archive
Using SSH on PHP help (SA-MP Commands) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Using SSH on PHP help (SA-MP Commands) (/showthread.php?tid=530676)



Using SSH on PHP help (SA-MP Commands) - ranme15 - 08.08.2014

Hello,

I am making a SA:MP panel with 3 options: Start, Pause and Restart.
The thing is, I made the connection to the linux user successfully, but the starting samp server command is not working, and I don't know why. Here is the code:
PHP код:
echo $ssh->write('cd samp01\n'); // Changing to 'samp01' directory
echo $ssh->write('./samp03svr &\n'); // Starting the server 
I have a 'samp01' folder inside of the user folder so I have to do 'cd'.
However, when I make these commands on Putty it works great.
Any ideas?

By the way, I am using phpseclib.


Re: Using SSH on PHP help (SA-MP Commands) - SKAzini - 08.08.2014

See if the working directory for the plugin is the same as the putty working directory by using pwd.


Re: Using SSH on PHP help (SA-MP Commands) - ranme15 - 08.08.2014

Quote:
Originally Posted by SKAzini
Посмотреть сообщение
See if the working directory for the plugin is the same as the putty working directory by using pwd.
May you explain yourself better please? thanks for reply though


Re: Using SSH on PHP help (SA-MP Commands) - SKAzini - 08.08.2014

PHP код:
echo $ssh->write('pwd\n'); 
Try this, it should (I'm not experienced with this plugin) print your working directory.

What does it return?


Re: Using SSH on PHP help (SA-MP Commands) - ranme15 - 08.08.2014

Quote:
Originally Posted by SKAzini
Посмотреть сообщение
PHP код:
echo $ssh->write('pwd\n'); 
Try this, it should (I'm not experienced with this plugin) print your working directory.

What does it return?
/home/samp01 (the user is samp01, but there is a directory in it called 'samp01' either)


Re: Using SSH on PHP help (SA-MP Commands) - SKAzini - 08.08.2014

PHP код:
echo $ssh->write('nohup ./samp03svr &\n'); 
Try this.

If that doesn't work, please print the folders in your home directory:

PHP код:
echo $ssh->write('dir\n'); 
And in your server folder:

PHP код:
echo $ssh->write('dir samp01\n'); 



Re: Using SSH on PHP help (SA-MP Commands) - ranme15 - 08.08.2014

Quote:
Originally Posted by SKAzini
Посмотреть сообщение
PHP код:
echo $ssh->write('nohup ./samp03svr &\n'); 
Try this.

If that doesn't work, please print the folders in your home directory:

PHP код:
echo $ssh->write('dir\n'); 
And in your server folder:

PHP код:
echo $ssh->write('dir samp01\n'); 
Before I do that, I am not sure if I have to use 'write' or 'exec'.
When I use 'write' it like writes '1' as output, but when I used 'exec' it doesn't give any output (as needed I guess).
Anyways, I used:
PHP код:
echo $ssh->exec('cd samp01');
echo 
$ssh->exec('nohup ./samp03svr &');
echo 
$ssh->exec('dir'); 
Output: 'samp01'

--

EDIT: In my server folder:
PHP код:
echo $ssh->exec('dir samp01'); 
Output: LICENSE announce gamemodes npcmodes samp03svr server.cfg README filterscripts include samp-npc scriptfiles server_log.txt


Re: Using SSH on PHP help (SA-MP Commands) - SKAzini - 08.08.2014

Strange..

PHP код:
echo $ssh->exec('nohup ./samp03svr &'); 
Should work..

Well, I'll try the plugin on my webserver and see if it works for me, posting the results in a while.


Re: Using SSH on PHP help (SA-MP Commands) - ranme15 - 08.08.2014

Quote:
Originally Posted by SKAzini
Посмотреть сообщение
Strange..

PHP код:
echo $ssh->exec('nohup ./samp03svr &'); 
Should work..

Well, I'll try the plugin on my webserver and see if it works for me, posting the results in a while.
I just realised that "echo $ssh->write('cd samp01\n');" doesn't really change the directory, which means the command is not even working. I have no clue why and how, but I will keep trying.

However, thank you very much!


Re: Using SSH on PHP help (SA-MP Commands) - SKAzini - 08.08.2014

Yeah, I just realised that too.

Workaround:

PHP код:
echo $ssh->exec('(cd samp01 ; nohup ./samp03svr &)');