在home目录下创建.expect目录,并添加两个文件: expect登陆脚本ssh-login.exp #!/usr/bin/expect -fset timeout 30set host [
在home
目录下创建.expect
目录,并添加两个文件:
- expect登陆脚本
ssh-login.exp
#!/usr/bin/expect -fset timeout 30set host [lindex $argv 0]set port [lindex $argv 1]set user [lindex $argv 2]set password [lindex $argv 3]spawn ssh -p $port $user@$hostexpect { "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.shfi