当我使用python pexpect库执行ssh时,bash提示有所不同

时间:2019-01-30 11:01:31

标签: python ssh spawn pexpect

当我使用ssh连接到Linux时,bash提示符为centos-1:~#

但是当我使用pexpect生成Linux连接时,bash提示符为\x1b]0;root@centos-1:~\x07centos-1:~# \r\n。 是什么导致此更改,如何摆脱此问题?

请在下面找到区别。

>>> import pexpect
>>> child = pexpect.spawn("/bin/ssh",["root@172.23.63.10"]);
>>> child.readline();
'#############################################################\r\n'
>>> child.readline();
'#                                                           #\r\n'
>>> child.readline();
'#  This system is restricted to authorized users only.      #\r\n'
>>> child.readline();
'#  Unauthorized access or access attempts to this system    #\r\n'
>>> child.readline();
'#  or services are prohibited. All user activity is logged. #\r\n'
>>> child.readline();
'#  Evidence of unauthorized use collected during monitoring #\r\n'
>>> child.readline();
'#  may be provided to appropriate personnel for             #\r\n'
>>> child.readline();
'#  administrative, criminal or other adverse action.        #\r\n'
>>> child.readline();
'#                                                           #\r\n'
>>> child.readline();
'#############################################################\r\n'
>>> child.readline();
'X11 forwarding request failed on channel 0\r\n'
>>> child.readline();
'Last login: Wed Jan 30 08:48:32 2019 from 10.70.52.187\r\r\n'
>>> child.readline();
'#############################################################\r\n'
>>> child.sendline("");
1
>>> child.readline();
'\x1b]0;root@centos-1:~\x07\x1b[?1034hcentos-1:~# \r\n'
>>> child.sendline("");
1
>>> child.readline();
'\x1b]0;root@centos-1:~\x07centos-1:~# \r\n'
>>> child.sendline("");
1
>>> child.readline();
'\x1b]0;root@centos-1:~\x07centos-1:~# \r\n'

[greddy] # ssh root@172.23.63.10
#############################################################
#                                                           #
#  This system is restricted to authorized users only.      #
#  Unauthorized access or access attempts to this system    #
#  or services are prohibited. All user activity is logged. #
#  Evidence of unauthorized use collected during monitoring #
#  may be provided to appropriate personnel for             #
#  administrative, criminal or other adverse action.        #
#                                                           #
#############################################################
X11 forwarding request failed on channel 0
Last login: Wed Jan 30 08:51:17 2019 from 10.70.52.187
#############################################################
centos-1:~#
centos-1:~#

0 个答案:

没有答案