clamphealth check
[oom.git] / kubernetes / portal / resources / scripts / update_hosts.sh
1 #!/bin/sh
2
3 _SRC_HOST=$1
4 _DST_HOST=$2
5 _IP=`getent hosts ${_SRC_HOST}|cut -d' ' -f1`
6 if [ -z ${_IP} ]; then
7   echo "Cannot retreive IP for host mapping ${_SRC_HOST} -> ${_DST_HOST}"
8   exit 1
9 fi
10 _REGEX=".*[[:blank:]]${_DST_HOST}$"
11 if grep -c -e "${_REGEX}" /etc/hosts > /dev/null 2>&1 ; then
12   cp /etc/hosts /tmp/hosts
13   sed -i "s/${_REGEX}/${_IP} ${_DST_HOST}/g" /tmp/hosts
14   cp /tmp/hosts /etc/hosts
15 else
16   echo "${_IP} ${_DST_HOST}" >> /etc/hosts
17 fi