Script per autogenerare file host

Questo è uno script da poter installare sulla propria macchina server, per autogenerare (con un bel cron) file host da poter poi scaricare con uno script impostato nel vostro router.

Questo per avere file host sempre aggiornati.


rm -rf /opt/ads/*

# Perform work in temporary files

# Obtain various hosts files and merge into one
wget -qO - >> $temphosts1
wget -qO - >> $temphosts1
wget -qO - >> $temphosts1
wget -qO - "" >> $temphosts1
wget -qO - >> $temphosts1
wget -qO - >> $temphosts1

# Do some work on the file:
# 1. Remove MS-DOS carriage returns
# 2. Delete all lines that don't begin with
# 3. Delete any lines containing the word localhost because we'll obtain that from the original hosts file
# 4. Replace with because then we don't have to wait for the resolver to fail
# 5. Scrunch extraneous spaces separating address from name into a single tab
# 6. Delete any comments on lines
# 7. Clean up leftover trailing blanks
# Pass all this through sort with the unique flag to remove duplicates and save the result

sed -e 's/\r//' -e '/^!d' -e '/localhost/d' -e 's/' -e 's/ \+/\t/' -e 's/#.*$//' -e 's/[ \t]*$//' < $temphosts1 | sort -u > /opt/ads/hosts

rm /var/www/MIOSITO/hosts.txt
ln /opt/ads/hosts /var/www/MIOSITO/hosts.txt

exit 0

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

Anti-Spam Quiz:


Questo sito usa Akismet per ridurre lo spam. Scopri come i tuoi dati vengono elaborati.