0

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 "\\$ $
Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
Rajeev
  • 44,985
  • 76
  • 186
  • 285
  • Check is there a RSYNC_PASSWORD in environment setting ? Or is public key used in targeted server? (in this case, remove the key) – ajreal Nov 26 '10 at 07:51

1 Answers1

0

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/
PleaseStand
  • 31,641
  • 6
  • 68
  • 95
  • I don't recommend using environment variables on a shared machine; *every* user on the machine can read *all* the environment variables of every process (it just requires some extra options to `ps`). – Donal Fellows Nov 26 '10 at 09:42