0

My script look like this , but not getting the password out.

#!/usr/bin/bash
export -p curdir=`basename ${PWD%/*/*/}`
/usr/bin/expect <<EOF
spawn scp -v -i ... <local file> <remote file containing $curdir>
expect -re "Enter passphrase.+:"
send "<password>\n"
exit;
EOF
exit

Something is wrong, as the passsword is evidently not sent. Something wrong with the expect line, the send line, or ??? When this script is executed it is asking for the password. Thanks for any help.

  • 1
    It's not convenient to embed Expect in shell. If you are more comfortable with shell syntax you can try my [sexpect (Expect for Shells)](https://github.com/clarkwang/sexpect). Here's an [example](https://stackoverflow.com/questions/63447519/). – sexpect - Expect for Shells Aug 18 '20 at 02:10
  • @FredKrogh : Or, alternatively, if you want to use Tcl/Expect, my recommendation is to not embed it and use bash variable substitution to squeeze in the changing part, but keep the expect script as a completely separate Tcl file and use parameter passing via command line arguments or environment variables to hand over the parameters to your script. – user1934428 Aug 18 '20 at 05:18
  • sexpect looks perfect, but if I am to download it, I need some help. I've been to the github page, and from there have downloaded some things. I have not used git, and there must be something I'm missing. I thought "git-receive-pack https://github.com/clarkwang/sexpect.git" might work but it does not appear to be a git repository – Fred Krogh Aug 18 '20 at 11:43
  • Obligatory question: have you considered using public-key authentication, bypassing the need for a password at all? – chepner Aug 18 '20 at 21:21
  • Haven't considered it. Destination requires a password. Happy with what now is working. – Fred Krogh Aug 19 '20 at 12:09

1 Answers1

0

I made this way too hard. ftp does everything I needed to do. And there are lots of places on the internet that explain how to use it. One can define bash variables as part of a bash script, and the password is simply part of what you define. scp is great of one copy, but ftp as part of a script is really easy.