2010-11-26 27 views
0

在以下期望腳本中,我注意到腳本甚至在提示輸入密碼之前會發送密碼。這怎麼能被阻止?我可以使用等待語句嗎?在腳本中使用等待

#!/usr/bin/expect -f 
#set timeout 25 
spawn rsync [email protected]:'/usr/backups /usr/backup-scripts /root/test/' /root/ 
expect "[email protected]'s password: $" 
send "\$xxxxxx\n" 
expect "\\$ $ 
+0

檢查有沒有在環境設置一個RSYNC_PASSWORD?或者是目標服務器中使用的公鑰? (在這種情況下,請刪除密鑰) – ajreal 2010-11-26 07:51:21

回答

0

您甚至不需要爲此任務使用expect。按照man page,rsync的支持的選項直接從文件中讀取密碼:

rsync --password-file=file_that_password_is_in [email protected]:'/usr/backups /usr/backup-scripts /root/test/' /root/ 

或者使用環境變量:

export RSYNC_PASSWORD=secret 
rsync [email protected]:'/usr/backups /usr/backup-scripts /root/test/' /root/ 
+0

我不建議在共享機器上使用環境變量; *機器上的每個*用戶都可以讀取每個進程的所有環境變量(它只需要一些額外的選項到「ps」)。 – 2010-11-26 09:42:05