Home | News | Download | Packages | Forum | Wiki | Github

How to update a file from internet every now and then?


I use this file to block ads on my computer.


But new adservers pop up everytime and those are added to this file by the community. It’s like a game of cat and mouse. So, the host file becomes obsolete very quickly. I was wondering if there is any way for my computer to check if a newer file is present and if it does, then download and replace it with my systems /etc/hosts.

I check the file manually every now and then and restart my computer. I know that runit has some way to restart the service without rebooting but I donn’t know. So, is there a way to automate this process.

(maxice8 alter) #2




which service are you talking about? :neutral_face:

(Dario Niedermann) #4

For the “checking” part, I wrote a Bash script years ago when I had the same need. You might find it useful it as a starting point.


I have a short script, like so:


TMPFILE=$(mktemp /tmp/adblockXXX)

echo -n "Attempting to download adlist: "


/usr/bin/wget -q -O $TMPFILE $FULLURL 2>/dev/null 1>&2

if [ $? -ne 0 ]; then
    echo 'Failed!'

echo 'Done!'

if [ ! -r $TMPFILE ]; then
    echo "Can't read file."
    echo "Copying downloaded file into place."
    /bin/mv $TMPFILE /etc/hosts.adblock
    /bin/chmod 0644 /etc/hosts.adblock
    echo "Updating DNS server."
    /bin/sv restart dnsmasq

And a runit service using snooze:


exec /bin/snooze -w 0 /usr/local/bin/update-adblock

That should run once a week.

(John Peach) #6

This is trivial with a cronjob that uses wget -qN and a makefile that runs if a new file has been downloaded…

Here is mine for root.hints

cd /etc/unbound
wget -qN ftp://rs.internic.net/domain/named.root
make -s
exit 0

…and the Makefile:

all: root.hints

root.hints: named.root
cp named.root root.hints
sv restart unbound