dthjnc306679 2014-07-30 06:09
浏览 160

phpseclib SSH2:为什么我的命令不运行?

I'm trying to make a web interface for managing my Ubuntu hosted Minecraft server. I use screen in order to make the console re-accessible. I don't get why the following code does not work:



    $ssh->read('quadrplax@quadrplax-laptop:~$');
    $ssh->write("screen -rd
");
    $ssh->write("stop
");

Now, don't ask me why, but if I add in this useless code:



    $randid=rand(0, 1000000);
    $consolemsg=strval($randid);

    $ssh->read('quadrplax@quadrplax-laptop:~$');
    $ssh->write("screen -rd
"); // note the "
"
    $ssh->write("say Stopping server - ID:".$consolemsg."
");
    echo $ssh->read(" [INFO] [Minecraft-Server] [Server] Stopping server - ID:".$consolemsg);
    $ssh->write("stop
");

Then it will be able to get the screen session disconnected, but the page will then load for minutes before timing out. Sorry for how stupid this is, I can't find any good guides for phpseclib, they all are copies of the same guide and don't give any long examples. I have been able to get some things to work, for example my suspend code somehow works:



    $ssh->read('quadrplax@quadrplax-laptop:~$');
    $ssh->write("sudo pm-suspend
");
    $ssh->setTimeout(5);
    $output = $ssh->read('#[pP]assword[^:]*:|quadrplax@quadrplax-computer:~\$#', NET_SSH2_READ_REGEX);
    $ssh->write("FAKEPASSWORD
");

Sorry for formatting errors or anything, first time here. I had a hard time getting this post to submit. Can someone help me out with this?

Edit: Fixed a copy-paste error

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 arduino控制ps2手柄一直报错
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥85 maple软件,solve求反函数,出现rootof怎么办?
    • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题
    • ¥15 Visual Studio问题
    • ¥20 求一个html代码,有偿
    • ¥100 关于使用MATLAB中copularnd函数的问题