Server SH script automatic login (MAC)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.