简体   繁体   中英

Using wait in a script

In the following expect script, I noticed that the script will send the password even before prompted for the password. How can this be prevented? Could I use a wait statement or something?

#!/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 "\\$ $

You shouldn't even need to use expect for this task. According to the man page , rsync supports an option to read a password directly from a file:

rsync --password-file=file_that_password_is_in root@14.12.123.82:'/usr/backups /usr/backup-scripts /root/test/' /root/

Or using an environment variable:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM