Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using 'expect' to automatically send in password [duplicate]

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?

like image 391
Saobi Avatar asked Jun 25 '09 16:06

Saobi


2 Answers

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
}
like image 71
Eden Avatar answered Sep 20 '22 13:09

Eden


While I agree with Sam and nik, the answer to you questions is that you didn't "hit enter":

send "mypassword\r"
like image 37
glenn jackman Avatar answered Sep 17 '22 13:09

glenn jackman