需要通过SSH在Python中向服务器发送命令的帮助
我正在尝试通过ssh连接到服务器,并把“df -h”的输出结果保存到一个文本文件里。
p=pexpect.spawn('ssh some.some.com')
i=p.expect([ssh_newkey,'password:',pexpect.EOF])
if i==0:
print "I say yes"
p.sendline('yes')
i=p.expect([ssh_newkey,'password:',pexpect.EOF])
if i==1:
p.sendline("somesome")
p.expect(pexpect.EOF)
i = p.sendline('df -h > /home/test/output.txt')
print i
response = p.before
print response
print p.before
我想连接到服务器,把服务器的数据保存到一个文本文件中。 我遇到的问题是,i = p.sendline('df -h > /home/test/output.txt') 这行代码没有任何反应, 也就是说我的输出文件是空的。 请帮帮我。
谢谢。