#!/bin/sh

hosts=$(get_hosts)
printf "%s" "$hosts" > "$1"

while sleep 2
do
  current_hosts=$(get_hosts)
  [ "$hosts" != "$current_hosts" ] && printf "%s" "$current_hosts" > "$1"
  hosts=$current_hosts
done