Skip to content

Instantly share code, notes, and snippets.

@denis
Created April 19, 2014 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save denis/11095215 to your computer and use it in GitHub Desktop.
Save denis/11095215 to your computer and use it in GitHub Desktop.
ZyXEL Keenetic /media/DISK_A1/system/etc/init.d/S15hosts
#!/bin/sh
RELOAD_DNS="killall -HUP dnsmasq"
start() {
if [ ! -f /var/hosts~ ]; then
cp /var/hosts /var/hosts~
flash STATICLEASE_TBL | while read line; do
ip=`echo $line | cut -f3 -d ";" | cut -f2 -d "=" | sed 's/"//g'`
host=`echo $line | cut -f4 -d ";" | cut -f2 -d "=" | sed 's/"//g'`
if ! grep -q "$ip $host" /etc/hosts; then
echo "$ip $host" >> /etc/hosts
fi
done
$RELOAD_DNS
fi
}
stop() {
if [ -f /var/hosts~ ]; then
mv /var/hosts~ /var/hosts
$RELOAD_DNS
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop}"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment