Skip to content

Instantly share code, notes, and snippets.

@c-garcia
Created September 19, 2015 05:57
Show Gist options
  • Save c-garcia/4adc977aae3a1f3c976b to your computer and use it in GitHub Desktop.
Save c-garcia/4adc977aae3a1f3c976b to your computer and use it in GitHub Desktop.
rsync a path when it is not possible use ssh key pairs (warning, warning, warning)
#!/usr/bin/expect
# Example script for rsync-ing a path when
# it is not possible to use ssh keys.
# This is not good practice. Adding a password
# to a file never is. Even less when it is used
# to bypass some security mechanisms implemented by
# ssh.
# It should be used only in very specific situations.
# It is left here for reference.
set file [lindex $argv 0];
# Disable logging
log_user 0
set timeout 10800
spawn "/bin/bash"
# Matches $ or #
expect -re {[$#] }
send "rsync -avz '$file' USER@HOST:/PATH/\r"
expect "password: "
sleep 1
# Danger, Will Robinson!
send "YOUR_PASSWORD\r"
log_user 1
expect -re {[$#] }
log_user 0
send "exit\r"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment