0

I need to do an sftp login in a shell script with bash. I have seen some examples here with expect. The problem is that I need to insert a password that is read from the input of the user, that is, I need something like

echo "Insert password: "
read my_passwd

and then I would send the my_passwd. So I would like an script like

echo "Insert password: "
read my_passwd

spawn sftp usr@example.com
expect "password: "
send "$my_passwd\n"

expect "sftp>"
send "get mbr*"

expect "sftp>"
send "bye\n"

but echo and read don't run. Even with this solution of adding exec (exec read my_passwd) before I still get an error (Run local command from expect script)

David
  • 1,155
  • 1
  • 13
  • 35
  • `echo` and `read` are shell script commands, not `expect` commands. – tripleee Jul 11 '19 at 11:12
  • 1
    take a look at [sexpect (Expect for Shells)](https://github.com/clarkwang/sexpect) which you can use to write *Expect* scripts with **shell code only**. – pynexj Jul 11 '19 at 11:15
  • 1
    See an simple example: [sftp-with-sexpect](https://i.stack.imgur.com/brp0M.png) – pynexj Jul 12 '19 at 02:22

0 Answers0