SCPを実行してリモートサーバーからファイルをコピーしようとしています。 root権限を持っていないので、パスワードを要求されたときにコマンドでsudoを使用します。pexpectを使用して送信していますが、実行できません。私はどこかに打たれました。
これが私のコードです:
import pexpect
def doScp(user,password,host,remotepath,localpath,files):
    print files
    child = pexpect.spawn('sudo scp -C %s:%s%s %s' % (host, remotepath, files, localpath))
    print 'scp -C %s:%s%s %s' % (host, remotepath, files, localpath)
    i = child.expect(['assword:', r"yes/no"], timeout=30)
    if i == 0:
        child.sendline(password)
    elif i == 1:
        child.sendline("yes")
        child.expect("assword:", timeout=30)
        child.sendline(password)
    data = child.read()
    print data
    child.close()
user = "xxxxx"
host = "yyyy"
password = "zzzzzz"
remotepath = "/opt/logs/"
localpath = "/opt/Performance_Logs/SRNG/"
files = "receiver.log"
doScp(user,password,host,remotepath,localpath,files)
私が得ているエラー:
ファイル "/usr/lib/python2.6/site-packages/pexpect.py"、行1325、expect_listの中でself.expect_loop(searcher_re(pattern_list)、timeout、searchwindowsize)を返すsite-packages / pexpect.py "、1409行目、expect_loopのTIMEOUTを上げます(str(e)+ '\ n' + str(self))
                   ファイル "/usr/lib/python2.6/site-packages/pexpect.py"、行1325、expect_listの中でself.expect_loop(searcher_re(pattern_list)、timeout、searchwindowsize)を返すsite-packages / pexpect.py "、1409行目、expect_loopのTIMEOUTを上げます(str(e)+ '\ n' + str(self)) 
                
                
                  
                    —
                    Rajesh