So, I wanted to automate my SSH logins. The host I'm working with does not allow key verification on this server, so I have to be more inventive.
I have little knowledge of shell scripts, but some research has shown me the "expect" command and some scripts that use it specifically for this purpose. I configured the script and ran it, it worked great for login.
#!/usr/bin/env expect -f set password "my_password" match_max 1000 spawn ssh -p 2222 "my_username"@11.22.11.22 expect "*?assword:*" send -- "$password\r" send -- "\r" expect eof
Initially, it works as it should.
Last login: Wed May 12 21:07:52 on ttys002 esther:~ user$ expect expect-test.exp spawn ssh -p 2222 my_username@11.22.11.22 my_username@11.22.11.22 password: Last login: Wed May 12 15:44:43 2010 from 20.10.20.10 -jailshell-3.2$
But where success ends.
Commands do not work, but pressing the button introduces a new line. Arrow keys and other non-alphanumeric keys create characters like "^ [[C ',' ^ [[A ',' ^ [OQ, etc.] [1]
No other prompt appears except for the two originally created in anticipation of the script. Any ignored commands will be executed by my local shell as soon as you expect time. Example:
-jailshell-3.2$ whoami ls pwd hostname
(... time passes, expect a delay) ...
esther:~ user$ whoami user esther:~ ciaran$ ls Books Documents Movies Public Code Downloads Music Sites Desktop Library Pictures expect-test.exp esther:~ ciaran$ pwd /Users/ciaran esther:~ ciaran$ hostname esther.local
As I said, I do not have shell scripts, but I think this is because I am still expecting "inside", but not "inside" SSH. Is there a way to stop waiting as soon as I log in and pass me an SSH session?
I tried commands like "close" and "exit", after "send -" \ r "". Yes, they do what I want and wait for death, but he vindictively takes away the SSH session, leaving me where I started. I really need to wait for my work to complete and stop, leaving the SSH session in my hands, as if I did it manually.
All help is appreciated, thanks. [1] I know what this name is, but I do not know what it is. And this is one of those frightening things that cannot be used for searching, since punctuation is ignored. As a question, what is the plot here?