在系統bin目錄中建立兩個腳本分別是pssh tssh
pssh
#!/usr/bin/expect -f set ip [lindex $argv 0 ] set port [lindex $argv 1 ] set password [lindex $argv 2 ]
set uname [lindex $argv 3 ] set timeout 10 spawn ssh root@$ip -p$port expect { "*yes/no" { send "yes\r"; exp_continue} "*password:" { send "$password\rclear\r\r\r請小心使用,您現在登錄的服務器IP是:$ip,服務器名稱是:$uname" } } interact
tssh
#!/bin/sh echo "以下是你的所有服務器列表" echo "1.A服務器 192.168.100.11" echo "2.B服務器 192.168.100.12" echo "3.C服務器 192.168.100.13" echo "回車鍵退出" echo "請輸入對應數字,選擇你要登錄的服務器:\c" read input test $input = 0 case $input in 1)pssh 192.168.100.11 22 123456 A服務器;; 2)pssh 192.168.100.12 22 admin B服務器;; 3)pssh 192.168.100.13 22 root C服務器;; esac
記得將給腳本加上可執行權限
然后在終端上執行tssh出現如下結果
以下是你的所有服務器列表
1.A服務器 192.168.100.11
2.B服務器 192.168.100.12
3.C服務器 192.168.100.13
回車鍵退出
請輸入對應數字,選擇你要登錄的服務器:1
spawn ssh root@192.168.100.11 -p22
CentOS release 6.8 (Final)
Kernel \r on an \m
root@192.168.100.11's password:
Last login: Thu Aug 18 18:34:58 2016 from 192.168.100.2
Welcome to aliyun Elastic Compute Service!
[root@Official ~]#