#!/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
-----------------------------------------------------------------"
}
while true
do
showMENU
read mychoice
echo
case "$mychoice" in
[Qq])
clear
exit
;;
[1-5])
IP=`grep "$mychoice. " $SERVERIP | awk '{print $2}'`
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