Recently often to login to the server via SSH, each time to enter a command and password is very troublesome, check the data found there are two solutions, one is to create a local key directly to log in, the other is to write a script.
Here we introduce the second method, the first kind of information is also many, but feel no meaning.
First on the script:
#!/usr/bin/expect-ssh"password : " " password\r"interact
One more line to explain:
The first explanation of this expect command, according to its Chinese meaning can also be guessed, is expected to appear, and then I will be based on the content of the next to send what (that is, the Send command).
The meaning of the spawn here is not associated with its function, Spawn is the command under expect, so the path of expect must be declared at the beginning of the script. According to other people's blog know its role is:
Its main function is to add a shell to the SSH running process to pass the interactive instructions.
OK, this basically can understand what this script is doing, first of all, the SS command, when the input password prompt, send a password, then enter your interaction with the server mode.
Done, the other commands with interactive, can be divert, extrapolate.
Linux Automatic logon script with interactive