我正在使用ssh
登錄到攝像機,scp
tarball並從tarbal中提取文件,然後運行腳本。不過,我和Pexpect有問題。當壓縮包被複制時,Pexpect超時。似乎不等到它完成。然後它開始用untar命令做同樣的事情,我的代碼如下:使用pexpect的SCP tar文件
ssh_newkey = 'Are you sure you want to continue connecting'
copy = pexpect.spawn('ssh [email protected]')
i=copy.expect([ssh_newkey,'password:',pexpect.EOF])
if i==0:
copy.sendline('yes')
i=copy.expect([ssh_newkey,'password:',pexpect.EOF])
if i==1:
copy.sendline("service")
print 'Password Accepted'
copy.expect('[email protected]:')
copy.sendline('su - root')
i=copy.expect('Password:')
copy.sendline('root')
i=copy.expect('#')
copy.sendline('cd /tmp')
i=copy.expect("#")
copy.sendline('scp [email protected]:/home/user/tarfile.tar.gz .')
i=copy.expect([ssh_newkey,'password:',pexpect.EOF])
if i==0:
copy.sendline('yes')
i=copy.expect([ssh_newkey,'password:',pexpect.EOF])
else:
pass
copy.sendline('userpwd')
i=copy.expect('#')
copy.sendline('tar -zxvf tarfile.tar.gz bin/installer.sh')
i=copy.expect("#")
copy.sendline("setsid /tmp/bin/installer.sh /tmp/tarfile.tar.gz > /dev/null 2>&1 &")
elif i==2:
print "I either got key or connection timeout"
else:
pass
任何人都可以幫助找到解決方案嗎?
感謝
你可以關閉報價@的2DN線,所以它會打印更好? – 2010-06-16 14:51:48