How to implement automatic ssh login to servers and batch management using reverse CT

Source: Internet
Author: User

Shell code:

Copy codeThe Code is as follows :#! /Usr/local/bin/CT
Set PASSWD [lindex $ argv 1]
Set IP [lindex $ argv 0]
Set CMD [lindex $ argv 2]
Spawn ssh $ IP $ CMD
CT "(yes/no )? "{
Send "yesr"
Reset CT "password :"
Send "$ PASSWDr"
} "Password:" {send "$ PASSWDr"} "* host" {exit 1}
CT eof

Note:

The first line explains the subsequent program by using the keep CT command in the/usr/local/bin directory.
The second, third, and fourth lines obtain the IP address, logon password, and command to be executed from the command line parameters.
The fifth line is probably to trigger such an event and execute the ssh $ IP $ CMD command.
The interaction process between 6th and 11th rows of CT is complete.
If yes/no is read )? At the prompt, enter yes and press Enter. If you have read the password: String prompting you to enter the password, enter the user logon password (root user ).
Of course, if it is not the first login, if you have logged on before, when you enter ssh $ IP $ CMD and press enter, you will be prompted to enter the password, that is, the string "* password:" will be read :", at this time, enter the password and press enter (send "$ PASSWDr ").
In addition, if the host cannot be accessed, (yes/no )? And "password:" may not appear, the system will prompt:
"No route to host" to exit the program.

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.