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 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算