#!/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:
- EXPECT-C:-c parameter followed by string
- Spawn ssh [email protected] $host connection server
- 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
- Interact
Maintain interactive status after execution and give control to console
Automatically log on to the server shell script