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)