#!/bin/bash # this script updates hosts in /etc/hosts # currently the only applicable host is my homeserver (local or remote ip) while [[ true ]]; do localcheck=`nmap -sn 192.168.1.0/24 | grep debian` if [[ $localcheck ]]; then hb_ip=`echo $localcheck | sed 's/.*(\(.*\))/\1/g'` else hb_ip=`ping grothe.ddns.net -c 1 | grep PING | awk '{print $3}' | sed 's/(\|)//g'` fi #sed -i 's/'${hb_ip}'.*//g' /etc/hosts sed -i '/.*hb/d' /etc/hosts echo "${hb_ip} hb" >> /etc/hosts sleep 360 done