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
Post a Comment