blob: cd38fafb40cc320e6bf56e3fb72c19d87eea7261 [file] [log] [blame]
yurynd9f6ecd2017-11-09 20:07:02 +02001#!/bin/sh
2
3_SRC_HOST=$1
4_DST_HOST=$2
5_IP=`getent hosts ${_SRC_HOST}|cut -d' ' -f1`
6if [ -z ${_IP} ]; then
7 echo "Cannot retreive IP for host mapping ${_SRC_HOST} -> ${_DST_HOST}"
8 exit 1
9fi
10_REGEX=".*[[:blank:]]${_DST_HOST}$"
11if 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
15else
16 echo "${_IP} ${_DST_HOST}" >> /etc/hosts
17fi