简体   繁体   English

Python 运行 Linux 命令,然后将终端留给用户

[英]Python run a Linux command and then leave the terminal to user

I am writing a remote login script that should just run a command (log me in to a device via telnet or ssh) and then just leave the terminal to me.我正在编写一个远程登录脚本,它应该只运行一个命令(通过 telnet 或 ssh 将我登录到设备),然后将终端留给我。

I tried subrocess.Popen module and for windows host I managed to achieve what I needed, the script opens putty or SecureCRT via a cmd command logging me in and then stops leaving the window to me.我尝试了subrocess.Popen模块,对于 windows 主机,我设法实现了我所需要的,脚本通过 cmd 命令打开腻子或 SecureCRT 登录,然后停止将 Z05B8C74CBD96FBF2DE4C1A352702 留给我。

In Linux it's a little different though, I want the script to run a command in the terminal and then I should be able to continue working on the terminal myself.在 Linux 中它有点不同,我希望脚本在终端中运行命令,然后我应该能够自己继续在终端上工作。 I tried subrocess with not much luck.我尝试了subrocess ,但运气不佳。

I can achieve this with pexpect.interact() but it seems that it will be more efficient if after logging me in the python script stopped as it is not needed anymore, if it is possible of course.我可以使用pexpect.interact()来实现这一点,但如果在 python 脚本中登录我之后停止,因为它不再需要它似乎会更有效,当然如果可能的话。

Try pwntools http://docs.pwntools.com/en/latest/intro.html#making-connections试试pwntools http://docs.pwntools.com/en/latest/intro.html#making-connections

It has a nice interactive mode.它有一个很好的interactive模式。

Check the examples on the page I linked.检查我链接的页面上的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM