Reputation: 11
I am really stumped! I DONT WANT TO USE RSA AUTH SO PLEASE ABSTAIN.
#!/bin/bash
echo "Enter the server password"
read password
cd /home/mike/
# this is included the code below ->
/usr/bin/expect << EOD
set timeout -1
spawn scp file.txt server.com:/home
expect {
timeout { send_user "TIME OUT\n"; exit 1 }
"*assword: "
}
send "$password\r"
expect {
"s password: " { send_user "\nIncorrect Password. Login Failed.\n"; exit 1 }
"100%"
}
sleep 1
send "exit\r"
expect eof
This works and file.txt gets transferred to the server but I get this warning message ->
" line 44: warning: here-document at line 22 delimited by end-of-file (wanted `EOD')"
When I add EOD at the end after 'expect eof' it gives me this error ->
send: spawn id exp4 not open
while executing
"send "exit\r"
Any help would be appreciated. I am saying again I cant use pubkey auth so please dont suggest that.
Upvotes: 1
Views: 9704
Reputation: 2366
By replacing your last line:
expect eof
with:
EOD
I don't get the complaint anymore. Note that you cannot have any tabs (and maybe spaces as well?) before your EOD
tag (which you defined in your initial /usr/bin/expect
line.
Upvotes: 4
Reputation: 12027
Instead of trying to script this using expect
, you can simply use curl
to copy files to/from a remote host via scp or sftp, and pass the authentication credentials to the curl command like so:
curl sftp://remotehost.domain.com/path/to/remote/file --user username:password -o /path/to/local/file
Upvotes: 2