Using expect, spawn with scp


I'm currently trying to automate a file transfer using the scp command with a shell script and the expect package. Based on what I've seen it seems that I should have
#!/usr/bin/expect -f
But when I did that I still get the errors: line 33: spawn: command not found
couldn't read file "*Password:*": no such file or directory line 35: send: command not found line 36: interact: command not found

The code I have works something along these lines:

#!/usr/bin/expect -f

set pass "***********"

cd $repository
spawn scp -r user@host:/copyDirectory/ .
expect "*Password:*"
send "${pass}\r";

Best Solution

It's a bad practice to store passwords in scripts or any other file. Use SSH authentication keys instead.

Take a look at this tutorial.