#!/bin/bash
set -e
SYSNAMEC=`echo -e "\033[32m$SYSNAME\033[0m"`
USER=`whoami`
SERVERIP="/home/user/serverip.txt"
IPLIST=`cat $SERVERIP`
myreturn()
{
SAVEDSTTY=`stty -g`
stty -echo
stty raw
dd if=/dev/tty bs=1 count=1 2>/dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}
showMENU()
{
echo
clear
echo "
远程连接服务器工具
---------------------------------------------------------------
HostName:`hostname -i`
Date:`date`
UserName:`whoami`
----------------------------------------------------------------
$IPLIST
-----------------------------------------------------------------"
echo "请选择需要SSH连接的服务器,或者直接输入服务器IP地址: "
}
while true
do
showMENU
read mychoice
echo
case "$mychoice" in
[Qq])
clear
exit
;;
[1-5])
IP=`grep "$mychoice. " $SERVERIP awk ''`
ssh $USER@$IP
break
;;
*)
NUM=`grep " $mychoice$" $SERVERIP wc -l`
if [ $NUM -eq 1 ];then
ssh $USER@$mychoice
break
else
echo "输入的IP:[$mychoice]不在服务器列表中"
fi
;;
esac
echo
echo "请按任意键继续..."
myreturn
done
领取专属 10元无门槛券
私享最新 技术干货