Using 'expect' to automatically send in password

Saobi picture Saobi · Jun 25, 2009 · Viewed 16.1k times · Source

I am trying to copy a file from my remote server to my local. Here's my script to run it, by using 'expect' to automaticlally send in password

scp user@host:/folder/myFile ./
expect "Password: "
send "myPassword"

When I run this, it still prompts for "Password", what is wrong?

Answer

Eden picture Eden · Feb 28, 2013

This expect script does the job (thanks to 'zedwood' )

#!/usr/bin/expect -f
set filename [lindex $argv 0]
set timeout -1
spawn scp $filename [email protected]:/home/myusername/
set pass "mypassword"
expect {
        password: {send "$pass\r" ; exp_continue}
        eof exit
}