summaryrefslogtreecommitdiff
path: root/update_hosts
blob: 8754b7af049d1a0817a482d8ea5e9453f2f1f1fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/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