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 [email protected]:'/usr/backups /usr/backup-scripts /root/test/' /root/
expect "[email protected]'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:Or using an environment variable: