简体   繁体   中英

expect script inside bash script

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.

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.

无需尝试使用expect编写脚本,只需使用curl即可通过scp或sftp将文件复制到远程主机或从远程主机复制文件,然后将身份验证凭据传递给curl命令,如下所示:

curl sftp://remotehost.domain.com/path/to/remote/file --user username:password -o /path/to/local/file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM