2010-11-26 29 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