一个部分目标是定期连接到一系列主机并将一些日志同步回中央服务器的脚本在手动调用它时可以完美地工作,
python ./apex2zabbix.py --sync="Client_Service_Platform Emtity"
但是,当通过 cron 调用时,在远程 rsync 步骤中以 .EOF 结束,
command = "/usr/bin/rsync -e ssh -a %s --compress=9 -pgtov %s %s --exclude='*' %s@%s:%s%s %s" % (remote_rsync_binary, excluded_expression, filters_expression, user, ip, source_path, file_filter, target_path)
p = pexpect.spawn(command, timeout=360)
i = p.expect([ssh_new_conn,'[pP]assword:',pexpect.EOF])
print 'Initial pexpect command output: ', i
if i == 0:
# send 'yes'
p.sendline('yes')
i = p.expect(['[pP]assword:',pexpect.EOF])
if i == 0:
# send the password
p.sendline(passwd)
p.expect(pexpect.EOF)
elif i == 1:
# send the password
p.sendline(passwd)
p.expect(pexpect.EOF)
elif i == 2:
print "key or connection timeout"
pass
返回
Initial pexpect command output: 2
可能是什么原因造成的?谢谢