Linux uses expect scripts to automate remote machine logon

Source: Internet
Author: User
Tags aliases

First create a expect script ssh_expect with the following file contents:

#!/usr/bin/expect-fSethostname [lindex$argv 0]SetUser [lindex$argv 1]Setpasswd [lindex$argv 2]SetTimeout -SetForce_conservative1if{$force _conservative} {SetSend_slow { -.1}}spawn SSH$user@$hostname; expect {"*continue connecting (yes/no)?"{Send- S "Yes\r"; Exp_Continue}"*assword:"{Send- S "$passwd\ r"; }}interact

Then define some command aliases, such as:

alias   h101=‘ssh_expect 192.168.0.101 <user> <password>‘alias   h102=‘ssh_expect 192.168.0.102 <user> <password>‘

These aliases can be written to the ~/.BASHRC file.

Then execute h101 to automatically log on to the 192.168.0.101 machine.

Please indicate this address in the form of a link.
This address: http://blog.csdn.net/kongxx/article/details/48675885

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Linux uses expect scripts to automate remote machine logon

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.