ssh2 connection to linux over php -


i try update minecraft whitelist on php linux server. connection works dont know why didnt send command add user whitelist.

here code:

$name=$_post['name']; $mc=$_post['mc']; if($ssh = ssh2_connect('127.0.0.1', 22)) { if(ssh2_auth_password($ssh, 'root', 'password')) {     $stream = ssh2_exec($ssh, 'screen -r '.$mc.' && '.'whitelist add '.$name.' && whitelist reload');     stream_set_blocking($stream, true);     $data = '';     while($buffer = fread($stream, 4096)) {         $data .= $buffer;     }     fclose($stream);     echo $data; } } 

you joining commands && , of them executed 1 after in current shell, not inside screen. screen can execute commands inside selected session, it's own syntax. see this question, example, or manual. in case, command must this:

screen -s session_name -x stuff $'whitelist add user_name && whitelist reload\n' 

note \n symbol @ end of string. required in order execute command because screen not execute it, screen "send specified command running screen session" manual says. consider screen type command instead of you. , when typing command, must press enter/return execute it.

in php can execute command way:

$stream = ssh2_exec($ssh, "screen -s $mc -x stuff \$'whitelist add $name && whitelist reload\\n'"); 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -