-
Notifications
You must be signed in to change notification settings - Fork 1
/
go.sh
39 lines (31 loc) · 910 Bytes
/
go.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
CONFIG_FILE="/root/go/config.data"
#
# Config file content format :
# <svr name> <ip addr/domain> <ssh port> <username>
#
# e.g
# test-svr 192.168.1.1 22 root
#
showlist(){
echo -e "\tServer Name\tServer Addr\n\t==========================="
cat ${CONFIG_FILE} | grep -v "#" | awk '{printf("\t%s\t\t%s\n" ,$1,$2)}'
}
if [ $# -eq '0' ]; then
echo "Usage : go.sh [name]"
echo -e "\tServer List in [$CONFIG_FILE]: "
showlist
exit
fi
NAME=$1
echo "Now going $NAME"
CONFIG=$(cat ${CONFIG_FILE} | grep -v "#" | grep $NAME)
if [ -z "$CONFIG" ]; then
echo "No Config for $NAME FOUND , check config"
exit
fi
HOST=$(echo $CONFIG | awk '{print $2}')
PORT=$(echo $CONFIG | awk '{print $3}')
USER=$(echo $CONFIG | awk '{print $4}')
echo "Trying to login [$NAME] (${USER}@${HOST}:${PORT})"
ssh ${USER}@${HOST} -p ${PORT}