您的位置:首页 > 运维架构 > Linux

Linux通过expect配置自动登录

2017-07-25 00:00 633 查看
home
目录下创建
.expect
目录,并添加两个文件:

expect登陆脚本
ssh-login.exp


#!/usr/bin/expect -f

set timeout 30

set host [lindex $argv 0]
set port [lindex $argv 1]
set user [lindex $argv 2]
set password [lindex $argv 3]

spawn ssh -p $port $user@$host
expect {
"yes/no" { send "yes\r"; exp_continue }
"password:" { send "$password\r" }
}

interact


expect配置脚本
ssh-login.sh


# alias ssh-name="./expect/ssh-login.exp host port username password"
alias ssh-n1.cluster=".expect/ssh-login.exp 192.168.9.181 22 root cluster"
alias ssh-n2.cluster=".expect/ssh-login.exp 192.168.9.182 22 root cluster"
alias ssh-n3.cluster=".expect/ssh-login.exp 192.168.9.183 22 root cluster"
alias ssh-n4.cluster=".expect/ssh-login.exp 192.168.9.184 22 root cluster"
alias ssh-n5.cluster=".expect/ssh-login.exp 192.168.9.185 22 root cluster"

.bashrc
下添加

if [ -f ~/.expect/ssh-login.sh ]; then
. ~/.expect/ssh-login.sh
fi
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Linux expect