Python Telnetlib read_until()和expect()未检测到终端回波

Python Telnetlib read_until()和expect()未检测到终端回波,python,linux,telnetlib,Python,Linux,Telnetlib,我用python编写了一个脚本,它使用telnetlib模块将Telnett连接到linux设备中,运行install.sh文件,然后在完成后重新启动。在install.sh脚本完成后,我添加了一行代码,将echo“install complete”发送到终端。不幸的是,read_直到(“install complete”)和expect([“install complete”])都没有检测到此回音 tn = telnetlib.Telnet(ip) tn.read_until("login:

我用python编写了一个脚本,它使用telnetlib模块将Telnett连接到linux设备中,运行install.sh文件,然后在完成后重新启动。在install.sh脚本完成后,我添加了一行代码,将echo“install complete”发送到终端。不幸的是,read_直到(“install complete”)和expect([“install complete”])都没有检测到此回音

tn = telnetlib.Telnet(ip)
tn.read_until("login: ")
tn.write(user + "\n")
tn.read_until("Password: ")
tn.write(password + "\n")
tn.write("cd [file path to the install script]")#echoes "install complete" when finished
tn.write("./install.sh\n")
tn.read_until("install complete")  #where the process hangs returns None if I add timeout parameter

telnetlib是否无法访问echo语句,或者是否应使用其他模块或语言?如果我手动运行安装程序,我可以确认“install complete”(安装完成)会按预期进行响应。

显示的代码在cd命令后不包含换行符(“\n”),因此实际发送的数据可能是“cd somepath./install.sh\n”,这将不起作用


此外,我在这里避免使用术语“echo”,因为在telnet中,“echo”实际上是将您发送的字符发送回您的部分(用于远程echo)。在本例中,无论发生与否,read_until()都不会在意。简而言之,这根本不是echo的问题。

您确定“安装完成”实际上已经完成了吗?在不知道telnet如何处理这种情况的情况下:字符串可能会在本地缓冲区中结束,等待换行符或刷新到stdout。我将debug_级别设置为10,并查看install命令的发送位置,以及在调试输出中接收到它的输出,但无论出于何种原因,“install complete”永远不会出现在流中。有没有办法刷新缓冲区中存储的内容?read_until()显示为读取在调用它之前执行的命令。您确定它是“install complete\n”并且在echo之后有一个换行符。。。在install.sh中,那么命令实际执行了吗?