Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 通过pexpect调用ssh存在终端/显示问题_Bash_Ssh_Pexpect_Xterm - Fatal编程技术网

Bash 通过pexpect调用ssh存在终端/显示问题

Bash 通过pexpect调用ssh存在终端/显示问题,bash,ssh,pexpect,xterm,Bash,Ssh,Pexpect,Xterm,让下面的代码段登录到给定的主机并执行一组命令,然后让会话对用户可用 一切都按预期运行,只是术语“显示设置”不知怎么搞砸了 例如,ls显示未对齐的输出,vi未正确显示文件内容(附快照) 即使shell上的命令超过当前行,在该行中移动也无法正常工作 尝试了不同的选项,但没有任何效果 import pexpect, struct, fcntl, termios, signal, sys, os def sigwinch_passthrough (sig, data): s = struct.p

让下面的代码段登录到给定的主机并执行一组命令,然后让会话对用户可用

一切都按预期运行,只是术语“显示设置”不知怎么搞砸了

例如,
ls
显示未对齐的输出,
vi
未正确显示文件内容(附快照)

即使shell上的命令超过当前行,在该行中移动也无法正常工作

尝试了不同的选项,但没有任何效果

import pexpect, struct, fcntl, termios, signal, sys, os
def sigwinch_passthrough (sig, data):
    s = struct.pack("HHHH", 0, 0, 0, 0)
    a = struct.unpack('hhhh', fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ , s))
    global child
    child.setwinsize(a[0],a[1])

if len(sys.argv) <= 1:
    print "Usage: sys.argv[0] <ip>"
    sys.exit(1)

ip = sys.argv[1]
ip.strip()
print "10.2.12.",ip

child = pexpect.spawn('/usr/bin/ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no em7admin@10.2.12.%s' % ip, env=os.environ)
signal.signal(signal.SIGWINCH, sigwinch_passthrough)

child.setwinsize(400,400)
child.sendline('export TERM="xterm-256color"')

child.expect('password:.*', timeout=9)
child.sendline('em7admin')

child.expect ('.*\$ ')
child.sendline('sudo bash')
child.expect('.* password for.*:.*', timeout=9)

child.sendline('em7admin')
child.expect ('.*\# ')

child.sendline('unset TMOUT')
child.interact()
导入预期、结构、fcntl、termios、信号、系统、操作系统
def sig/U直通(sig,数据):
s=结构包(“hhh”,0,0,0,0)
a=struct.unpack('hhh',fcntl.ioctl(sys.stdout.fileno(),termios.TIOCGWINSZ,s))
全球儿童
child.setwinsize(a[0],a[1])

如果在远程系统上不运行
sudo
,则len(sys.argv)是否有效?否。它的相同行为似乎与
术语
变量有关。您可能应该使用
os.environ[“TERM”]
来获取实际值并将其传递。而窗口大小
400x400
似乎非常大。我刚刚用我的32英寸显示器的全宽创建了一个窗口,它只有84列宽。请看一下,您可以使用哪个窗口只使用shell代码编写Expect脚本。