Automatically log on to the server shell script

Source: Internet
Author: User

#!/bin/bash

#Description: Auto Login The remote server
#Author: Majinxu
#Version: 1.0
#CreateTime: 2018-3-012 18:34:41

User= "Majinxu"
Passwd= "! Ieric1234 "

host_list= ("st1.qa.bj2.yongche.com"
"St2.qa.bj2.yongche.com"
"St3.qa.bj2.yongche.com"
)

#seletc the Host
Select Host in ${host_list[@]};
Do
Break
Done

#execute the SSH action
Expect-c "
Spawn ssh [email protected] $host
Expect {
\ "yes\/no\" {send \ "yes\n\"; Exp_continue}
\ "Password:\" {Send \ "$passwd \n\"}
}
Interact
"

Explain:

    1. EXPECT-C:-c parameter followed by string
    2. Spawn ssh [email protected] $host connection server
    3. Expect {
      \ "yes\/no\" {send \ "yes\n\"; Exp_continue}
      \ "Password:\" {Send \ "$passwd \n\"}
      }
      Enter and receive user name password
      Is
      "Yes/no" {send "yes\n"; Exp_continue}
      "Password:" {send "$PASSWD \ n"}
      The result after escaping
    4. Interact
      Maintain interactive status after execution and give control to console

Automatically log on to the server shell script

Related Article

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.