2011-08-17 27 views
0

一個腳本部分的目標是週期性地連接到主機範圍和rsync某些日誌回中央服務器工作完美無缺手動調用它時,的Cron - 失敗調用外部腳本(環境變量初始化)

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='*' %[email protected]%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 

可能是什麼原因造成的? 感謝

回答

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 /斌/ rsync的-e的/ usr /斌/ SSH

command = "/usr/bin/rsync -e /usr/bin/ssh -a %s --compress=9 -pgtov %s %s --exclude='*' %[email protected]%s:%s%s %s" % (remote_rsync_binary, excluded_expression, filters_expression, user, ip, source_path, file_filter, target_path) 
相關問題