Shell 在脚本中使用wait

Shell 在脚本中使用wait,shell,rsync,expect,password-prompt,Shell,Rsync,Expect,Password Prompt,在下面的expect脚本中,我注意到脚本会在提示输入密码之前发送密码。如何防止这种情况?我能用一个等待声明或什么吗 #!/usr/bin/expect -f #set timeout 25 spawn rsync root@14.12.123.82:'/usr/backups /usr/backup-scripts /root/test/' /root/ expect "root@14.12.123.82's password: $" send "\$xxxxxx\n" expect "\\$

在下面的expect脚本中,我注意到脚本会在提示输入密码之前发送密码。如何防止这种情况?我能用一个等待声明或什么吗

#!/usr/bin/expect -f
#set timeout 25
spawn rsync root@14.12.123.82:'/usr/backups /usr/backup-scripts /root/test/' /root/
expect "root@14.12.123.82's password: $"
send "\$xxxxxx\n"
expect "\\$ $

对于此任务,您甚至不需要使用
expect
。根据,rsync支持直接从文件读取密码的选项:

rsync --password-file=file_that_password_is_in root@14.12.123.82:'/usr/backups /usr/backup-scripts /root/test/' /root/
或使用环境变量:

export RSYNC_PASSWORD=secret
rsync root@14.12.123.82:'/usr/backups /usr/backup-scripts /root/test/' /root/

检查环境设置中是否有RSYNC_密码?或者在目标服务器中使用公钥?(在本例中,请删除该键)我不建议在共享计算机上使用环境变量;机器上的每个用户都可以读取每个进程的所有环境变量(它只需要一些额外的选项来
ps
)。