testing: Enable ssh connection to second IP by name (e.g. moon1)
[strongswan.git] / testing / ssh
1 #!/bin/bash
2
3 DIR=$(dirname `readlink -f $0`)
4 . $DIR/testing.conf
5
6 if [ $# == 0 ]
7 then
8         echo "$0 <host>"
9         exit 1
10 fi
11
12 host=$1
13 echo "$host" | grep -q "^\([0-9]\+\.\|[0-9a-fA-F]\+:\).*"
14 if [ $? -eq 0 ]
15 then
16         # assume we got an ip address
17         ip=$host
18 else
19         pos='$1'
20         echo "$host" | grep -q ".*1$"
21         if [ $? -eq 0 ]
22         then
23                 # {host}1, use second address
24                 pos='$2'
25                 host=`echo "$host" | sed -n -e "s/1$//p"`
26         fi
27         ip="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, "{ print ${pos} }" | awk '{ print $1 }'`"
28         if [ -z $ip ]
29         then
30                 echo "Host '$host' unknown"
31                 exit 1
32         fi
33 fi
34
35 shift
36 exec ssh $SSHCONF -q root@$ip $@