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.