ruby ssh: interactive command “su”: How further after successfull logged in?

╄→尐↘猪︶ㄣ 提交于 2019-12-06 07:41:53

The problem is that su is creating a subshell, and net-ssh is controlling the outermost shell. Its just like running... emacs or something from net-ssh, you can't expect net-ssh to be able to know how to control that inner shell.

So what you have to do is when you detect su was successful, you have to send the data as if you were just typing it in, and then you can read the stdout. Unfortunately, you can't separate the stdout from the stderr since its in a subshell, but you can still get the output.

Instead of using ch.exec after suing successfully, use ch.send_data "command\n" and read the output. Don't forgot to end everything with a ch.send_data "exit\n". (Note that \n has to follow every command to simulate an enter keypress in the console)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!