Use login CT to implement SSH automatic password input, so as to automatically log on to Linux

Source: Internet
Author: User
Run the following command to execute the following documents and experiments on the Internet:

Keep CT-F expect-ssh.exp <username> <password>
Note that in this expect-ssh.exp, the connect function is mainly responsible for login, the last two lines of code, the two send is the login, the execution of the command, note that at last must execute an exit, otherwise, the secondary CT will remain on the remote host after execution.

Here is the source code of the expect-ssh.exp: Proc usage {}{
Puts stderr "usage :$: argv0 Username Password IPaddress"
Exit 1
}

Proc connect {pass }{
CT {
"(Yes/No )? "{
Send "Yes \ n"
Reset CT "* password :"{
Send "$ Pass \ n"
CT {
"*#"{
Return 0
}
}
}
}
"* Password :"{
Send "$ Pass \ n"
CT {
"*#"{
Return 0
}
}
}
}
Return 1
}

If {$ argc! = 3} {usage}

Set username [lindex $ argv 0]
Set Password [lindex $ argv 1]
Set hostip [lindex $ argv 2]

Spawn SSH $ {username }@$ {hostip}

If {[connect $ Password]} {
Exit 1
}

Send "RM-F/root/testeric; RM-F pattern_file \ n"
Send "Exit \ n"
CT EOF

 

 

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.