Tries the same but still getting prompted for password. Please help
---------- Post updated at 05:03 PM ---------- Previous update was at 10:18 AM ----------
Hi,
I have created a function in which I am trying to use the expect command for sftp but it is not working. While copying the same in another script(test.sh) it is working.
CAN YOU PLEASE LET ME KNOW WHY THE SAME IS NOT WORKING IN FUNCTION?
smsiuc_ftp
-bash: spawn: command not found
couldn't read file "ftp_dl@10.132.249.50's password:": no such file or directory
-bash: send: command not found
couldn't read file "sftp>": no such file or directory
-bash: send: command not found
couldn't read file "sftp>": no such file or directory
-bash: send: command not found
-bash: EOF: command not found
cat: output.log: No such file or directory
Null message body; hope that's ok
test.sh script in which sftp is used which is working fine is as follows
That's because neither spawn nor expect , send or EOF are bash commands; they're expect commands. A "shebang" (quite close to which you get in test.sh; remove the leading space) will run the script with the command indicated.
In post#1, the password might be requested because sftp is not run from within expect but as an independent command. Try embedding it in a here document (c.f. man bash )
Thanks RudiC for the comments. But we cannot set the expect in function which is my exact requirement. Can you please throw some light on this for the way out of using it in function?
Note that sftp is specifically designed to prevent you from doing what you are trying to do because it is an extremely bad and insecure method of transferring files. That is why you are forced to use the expect brute-force password injection tool to inject passwords into it brute-force. It would be better to cooperate with the way sftp is designed to work, and use passwordless keys.
Sorry for overquoting, but I skip all the answers already made And moderators should also have some fun with my posts.
If you look ag ssh source code, you will notice, that ssh asks for password in a specific manner:
/*
* Reads a passphrase from /dev/tty with echo turned off/on. Returns the
* passphrase (allocated with xmalloc). Exits if EOF is encountered. If
* RP_ALLOW_STDIN is set, the passphrase will be read from stdin if no
* tty is available
*/
ssh doesn't write to standard output, where expect waits for the string "password", that's why you can't handle sftp password prompt with your script.
I didn't want to waste too much time with your script and still don't know the correct answer, but:
your script works for me on my RHEL6 with expect 5.44