Skip to content

Instantly share code, notes, and snippets.

@darrylhebbes
Created April 3, 2013 21:12
Show Gist options
  • Save darrylhebbes/5305347 to your computer and use it in GitHub Desktop.
Save darrylhebbes/5305347 to your computer and use it in GitHub Desktop.
A script to pass password to SSH Rsync session, without using SSH Keys. NOTE: this is not a wise solution but useful in certain situations. Usage example 1: "./rsync-app.sh B" will spawn the Rsync in the second block, "./rsync-app.sh ABC" will run all three.
#!/usr/bin/expect -f
set MachineName "Macintosh HD"
set MachineUserProfile "computerprofile"
set ProjectPath "htdocs/yourlocalprojectname"
set RemoteLogin "[email protected]"
set RemoteProjectPath "/htdocs/myproject"
set PASSPH "theSSHpassword"
send_user "\n"
stty -echo
if { [lindex $argv 0] == "A" || [lindex $argv 0] == "ABC" } {
spawn rsync -aihv --exclude '.git' --exclude '.DS_Store' -e ssh "/Volumes/$MachineName/Users/$MachineUserProfile/$ProjectPath/htdocs/application/layouts/" "$RemoteLogin:$RemoteProjectPath/htdocs/application/layouts/"
expect "password:"
send "$PASSPH\n"
expect "#"
}
if { [lindex $argv 0] == "B" || [lindex $argv 0] == "ABC"} {
spawn rsync -aihv --exclude '.git' --exclude '.DS_Store' -e ssh "/Volumes/$MachineName/Users/$MachineUserProfile/$ProjectPath/htdocs/application/controllers/" "$RemoteLogin:$RemoteProjectPath/htdocs/application/controllers/"
expect "password:"
send "$PASSPH\n"
expect "#"
}
if { [lindex $argv 0] == "C" || [lindex $argv 0] == "ABC"} {
spawn rsync -aihv --exclude '.git' --exclude '.DS_Store' -e ssh "/Volumes/$MachineName/Users/$MachineUserProfile/$ProjectPath/htdocs/application/views/" "$RemoteLogin:$RemoteProjectPath/htdocs/application/views/"
expect "password:"
send "$PASSPH\n"
expect "#"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment