duanping5306 2015-02-24 01:22
浏览 36

ssh write()read()过早退出

I have written a piece of code that will install a software on the server. It all works perfectly but for one part of the code.

When i start using read() and write() it does what it should. I tell it to yum install several softs and then start screen so when the page would fail the install of the software would still continue. So that is all going well. Then i start with installing vestacp for example.

$ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX); 
$ssh->write("yum install screen wget -y
");
$ssh->setTimeout(10); 
$ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX);
$ssh->write("screen
");
$ssh->setTimeout(10);
$ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX);
$ssh->write("curl -O http://vestacp.com/pub/vst-install.sh
");
$ssh->setTimeout(10);
$ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX);
$ssh->write("bash vst-install.sh
");
$ssh->setTimeout(10);
$ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX);
$ssh->write("y
");
$ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX);
$ssh->write("webmaster@yourdomain.com
");
$ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX);
$ssh->write("vps.yourdomain.com
");
$ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX);
$ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX);
$output = $ssh->read('/.*@.*[$|#]|.*[P|p]assword.*/', NET_SSH2_READ_REGEX);

So it start the installation process. This is all activated from a ajax function and the data stored in output is being showed by jquery in a div.

But, and here is the problem. After about a minute ajax is getting the success data back and outputs the $output in a div. When i open the command line and reattach screen -r i see the install is still running. This is also the reason i use screen so i am certain that the process continues even when things go wrong in the browser.

So now i am looking for a solution to make sure that i do not see the output too soon. What if i would install something that is taking two hours. I want it to show my loading animation for like 2 hours. This is very important or it would like the software installed much faster then it really did.

Who can help me here.

thanks.

  • 写回答

1条回答 默认 最新

  • drux41001 2015-02-24 14:47
    关注

    The solution to my problem was really simple, the timeout was the problem as it was set to 10. This means that it outputs when the server is waiting for connection or to execute a process. Increasing it solved the problem.

    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法