Using Expect to automate an scp filetransfer

Sometimes you know passwords but are not ion a position to use shared keys. Solution is using expect to pass the password from a script read or a comman line parameter.

** NOTE Passwords in command lines are a really bad idea since you can see them in the history / ps -ef so best is to read from stdio and pass as a parameter.

 

 

#!/usr/bin/expect
spawn scp [lindex $argv 0] root@192.168.8.117:/vmfs/volumes/datastore1/
######################
expect {
-re "Password:" {
exp_send "[lindex $argv 1]\r"
}
}
interact


	

2 comments to “Using Expect to automate an scp filetransfer”

You can leave a reply or Trackback this post.
  1. I use Expect in many applications, but this simple and clear little program answered many questions and works perfectly.

Write a Reply or Comment

Your email address will not be published.