0

部分的な目標は、一定範囲のホストに定期的に接続し、一部のログを中央サーバーに再同期することであり、手動で呼び出すと問題なく動作します。

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

何が原因でしょうか?ありがとう

4

1 に答える 1

0

はあ…頭が止まっていなかったら、追加することを忘れなかったでしょう

print 'output:', p.before

そしてそれが戻ってきたことに気づいた

output: rsync: Failed to exec ssh: No such file or directory (2)

私の考えに反して、rsync -e の ssh はオプションではなくバイナリであるため、次のいずれかを追加する必要があります

PATH=/sbin:/bin:/usr/sbin:/usr/bin

cron またはフルパス形式を指定するには、/usr/bin/rsync -e /usr/bin/ssh

command = "/usr/bin/rsync -e /usr/bin/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)
于 2011-08-18T18:43:06.227 に答える