Accidentally oneself also have three virtual machine, each time ssh [email protected] and then in the input password really egg hurts, the first reaction when the script login, but as the script is line-by-row execution command, is unable to wait for a password prompt appears in the input password. Found under the Mac can be expect (specifically spawn,expect,send three functions), win similar also has expect tools. Feeling should be an operation and maintenance skill.
OK, install expect, according to Install,readme, to install expect status Tcl (another package), http://www.tcl.tk/software/tcltk/ Download.html,tcl words extracted I directly into the UNIX directory, because MACOSX under the readme said Mac as UNIX installed also no matter, and I macosx under make is what ghost ... Installation nothing to note,./configure make Makeinstall is enough. Installed TCL remember to look at the installation of the path, mine is in the/usr/local/lib/.
Then download the expect package, https://sourceforge.net/projects/expect/files/Expect/5.45/. Here decompression and put to Tcl together, my words that is/usr/local/lib/, and then make expect said can only install expect related components, there are other??? , no matter what, I'll install it directly after make.
Then we have the main function of expect.
The code is as follows:
#!/usr/bin/expect-F -1ssh [email protected]ServerIP " *assword:* " // Wait for password prompt display "$password \ r" // login Interact //done
And then it hurts that the script is not going to perform as normal sh. Must be executed with the expect command. Specific is expect mylogon.sh. chmod +x mylogon.sh During the period if not executed.
OK user password is inside the logon.sh.
Server SH script automatic logon (MAC)