Saturday, July 2, 2016

A Shell Script To Download MVPS Host File And Use It On Our OpenWRT Router


#!/bin/sh

hosts_file="/etc/hosts"
old_hosts_file="old_hosts.txt"
new_hosts_file="new_hosts.txt"

if [ -f $hosts_file ] ; then
    mv $hosts_file ./hosts
    rm -f $HOSTFILE
fi

if [ -f "hosts.txt" ] ; then
    rm -f ./hosts.txt
fi

if [ -f "new_hosts.txt" ] ; then
    rm -f ./new_hosts.txt
fi

cp /etc/hosts ./old_hosts.txt
cat ./hosts | sed -e 's/0\.0\.0\.0.*$/\r/g' -e '/^\s*$/d' > $HOSTFILE
wget http://www.mvps.org/winhelp2002/hosts.txt
cat ./hosts.txt | sed -e 's/^#.*$/\r/g' -e 's/\s*#.*$/\r/g' -e '/^\s*$/d' | sed -e '1,2s/^.*$//g' -e '/^\s*$/d' | sed -e 's/127\.0\.0\.1/0\.0\.0\.0/g' >> $HOSTFILE
#cat $HOSTFILE > /etc/hosts


#wget -O - http://www.mvps.org/winhelp2002/hosts.txt | grep 127.0.0.1 | sed -e '2,$s/127.0.0.1/0.0.0.0/g' -e 's/[[:space:]]*#.*$//' > /etc/hosts
#logger "$0: Hosts-file downloaded"stopservice dnsmasq
#startservice dnsmasq
#logger "$0: DNSMasq restarted"

No comments:

Post a Comment