Re: script bash pour unbound
----- Mail original -----
> De: "Daniel Caillibaud" <ml@lairdutemps.org>
> À: debian-user-french@lists.debian.org
> Envoyé: Mardi 21 Août 2018 19:21:06
> Objet: Re: script bash pour unbound
>
> Le 18/08/18 à 21:48, Bernard Schoenacker
> <bernard.schoenacker@free.fr> a
> écrit :
>
> > bonjour,
> >
> > j'ai pris ce script bash et je n'arrive pas à le déverminer:
> >
> > https://blog.mirabellette.eu/index.php?article17/block-advertise-domain-name-with-unbound
> >
> > voici le début qui pose problème :
> >
> > ARRAY=
> > $(https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn-social/hosts
> > )
>
> sur la page mentionnée y'a pas de $
>
> > for i in "${ARRAY[@]}"
>
> et du coup je comprend pas la ligne précédente, pourquoi un for sur
> un
> tableau d'un seul élément ?
>
> Pas testé, mais amha, virer do/done et remplacer le wget par
>
> > do
> > wget -c -O w "$i"
>
> wget -c -O w
> https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn-social/hosts
>
>
> >
> > grep -v "
> > #\|<td>\|<p>\|<meta>\|<link>\|<title>\|href\|title=\|=\|<" w
> > > adsList.txt rm -f w
> > dos2unix adsList.txt
>
>
> ça peut se faire sans fichier intermediaire avec
>
> wget -c -O - $url|grep -v "expression" > fichier
>
> donc ici tu peux te contenter de ces 3 lignes, en remplaçant la 3e
> par /etc/init, service ou systemctl suivant ta conf
> (et mettre le path complet de adsList.txt pour pouvoir lancer le
> script de
> n'importe où) :
>
> url=https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn-social/hosts
> wget -q -O - $url|sed -e '/^$/d; /#/d' > adsList.txt
> # reste à relancer unbound qui lit ce adsList.txt
>
>
> mais je crois qu'unbound ignore les lignes vides et celles qui
> commencent
> par #, ton script devrai#!/bin/bash
#
# set chmod +x
# exec sh
echo ================ Someonewhocares Go ===========================
wget -vnc -O - 'https://someonewhocares.org/hosts/zero/' |unhtml | grep '^0\.0\.0\.0' | awk '/0.0.0.0/ {print $2}'| iconv -f iso8859-15 -t utf8 >>w
echo convert file to utf8
echo ================ Someonewhocares done ==========================
echo ================ Githubusercontent notracking Go ===========================
wget -vnc -O - 'https://raw.githubusercontent.com/notracking/hosts-blocklists/master/hostnames.txt'| grep '^0\.0\.0\.0' | awk '/0.0.0.0/ {print $2}'| iconv -f iso8859-15 -t utf8 >>w
echo convert file to utf8
echo ================ Githubusercontent notracking done ===========================
echo ================ winhelp2002 Go ===========================
wget -vnc -O - 'http://winhelp2002.mvps.org/hosts.txt' |awk '/0.0.0.0/ {print $2}'| iconv -f iso8859-15 -t utf8 >>w
echo convert file to utf8
echo ================ winhelp2002 done ===========================
echo ================ Githubusercontent StevenBlack Go ===========================
wget -vnc -O - 'https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn-social/hosts' |awk '/0.0.0.0/ {print $2}'| iconv -f iso8859-15 -t utf8 >>w
echo convert file to utf8
echo ================ Githubusercontent StevenBlack done ===========================
echo ================ Adaway Go ===========================
wget -vnc -O - 'https://adaway.org/hosts.txt' | awk '/127.0.0.1/ {print $2}'| iconv -f iso8859-15 -t utf8 >>w
echo convert file to utf8
echo ================ Adaway done ===========================
echo ================ Pgl Yoyo Go ===========================
wget -vnc -O- --header\="Accept-Encoding: gzip" 'http://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&mimetype=plaintext' | gunzip | awk '/127.0.0.1/ {print $2}'| iconv -f iso8859-15 -t utf8 >>w
echo convert file to utf8
echo ================ Pgl Yoyo done ===========================
echo ================ Hosts File Go ===========================
wget -qnc -O - 'https://hosts-file.net/ad_servers.txt' | awk '/127.0.0.1/ {print $2}' | iconv -f iso8859-15 -t utf8 >>w
echo convert file to utf8
echo ================ Hosts File done ===========================
echo ================ dsfc Go ===========================
wget -qnc -O - 'https://www.dsfc.net/infrastructure/dns-infrastructure/unbound-redirecteur-cache-blacklist-dns/'|unhtml| tr -d '\<br/>'| tr -d '"' | awk '/local-zone/ {print $2}'| iconv -f iso8859-15 -t utf8 >>w
echo convert file to utf8
echo ================ dsfc done ===========================
echo remove tabulation character and carriage return
sed -i 's/\x0D$//' w
echo remove comments
sed -i 's/#//g' w
echo remove useless space
sed -i 's/ //g' w
echo remove empty lines
sed -i '/^\s*$/d' w
echo add prefix and suffix for unbound
echo "#" $(date +'%d-%m-%Y') >>adslist.txt
echo server: >>adslist.txt
cat w | sort -bdfu | awk '{print "local-zone: \""$1"\" redirect\nlocal-data: \""$1" A 127.0.0.1\""}' >adslist.txt
echo delete temporary file
rm -f w
echo download roots files
# wget -qnc -O /etc/unbound/root.hints ftp://ftp.internic.net/domain/named.cache
# wget -qnc -O root.hints ftp://ftp.internic.net/domain/named.cache
echo unbound restart
# systemctl restart unbound.service
exit 0
t pouvoir se résumer à
>
> url=https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn-social/hosts
> wget -q -O /path/to/adsList.tmp $url \
> && [ -s /path/to/adsList.tmp ] \
> && mv /path/to/adsList.tmp /path/to/adsList.txt \
> && systemctl reload unbound \
> && echo "Liste actualisée et rechargée" \
> || echo "Un truc a foiré">&2
>
> (l'enchaînement avec && est là au cas où le wget plante, pour ne pas
> risquer
> d'écraser l'ancien txt avec un truc vide, le test -s passe si le
> fichier
> n'est pas vide)
>
>
> Une remarque au passage, je ne laisserais pas qqun d'externe définir
> l'ip de localhost, ça me parait plus prudent d'ajouter un sed pour
> virer
> les premières lignes, ou ne garder que celles qui commencent par
> 0.0.0.0,
> en ajoutant si besoin un autre fichier txt pour unbound pour ces
> lignes
> (mais je crois qu'unbound résoud déjà localhost avec sa conf par
> défaut).
>
> wget -q -O - $url|sed -ne '/^0\.0\.0\.0/ p' > /path/to/adsList.tmp
>
>
> Celui qui fournit la liste pourra toujours rediriger localhost vers
> 0.0.0.0
> mais au moins ça n'ira pas ailleurs et je vais m'en apercevoir
> rapidement.
>
> >
> >
> > merci pour le coup de puce
> >
> > slt
> > bernard
> >
>
>
> --
> Daniel
>
> Travailler dur n'a jamais tué personne, mais pourquoi prendre le
> risque ?
> Edgar Bergen
>
bonjour,
j'ai tout repris le script et en recherchant j'ai trouvé d'autres liens :
#!/bin/bash
#
# set chmod +x
# exec sh
echo ================ Someonewhocares Go ===========================
wget -vnc -O - 'https://someonewhocares.org/hosts/zero/' |unhtml | grep '^0\.0\.0\.0' | awk '/0.0.0.0/ {print $2}'| iconv -f iso8859-15 -t utf8 >>w
echo convert file to utf8
echo ================ Someonewhocares done ==========================
echo ================ Githubusercontent notracking Go ===========================
wget -vnc -O - 'https://raw.githubusercontent.com/notracking/hosts-blocklists/master/hostnames.txt'| grep '^0\.0\.0\.0' | awk '/0.0.0.0/ {print $2}'| iconv -f iso8859-15 -t utf8 >>w
echo convert file to utf8
echo ================ Githubusercontent notracking done ===========================
echo ================ winhelp2002 Go ===========================
wget -vnc -O - 'http://winhelp2002.mvps.org/hosts.txt' |awk '/0.0.0.0/ {print $2}'| iconv -f iso8859-15 -t utf8 >>w
echo convert file to utf8
echo ================ winhelp2002 done ===========================
echo ================ Githubusercontent StevenBlack Go ===========================
wget -vnc -O - 'https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn-social/hosts' |awk '/0.0.0.0/ {print $2}'| iconv -f iso8859-15 -t utf8 >>w
echo convert file to utf8
echo ================ Githubusercontent StevenBlack done ===========================
echo ================ Adaway Go ===========================
wget -vnc -O - 'https://adaway.org/hosts.txt' | awk '/127.0.0.1/ {print $2}'| iconv -f iso8859-15 -t utf8 >>w
echo convert file to utf8
echo ================ Adaway done ===========================
echo ================ Pgl Yoyo Go ===========================
wget -vnc -O- --header\="Accept-Encoding: gzip" 'http://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&mimetype=plaintext' | gunzip | awk '/127.0.0.1/ {print $2}'| iconv -f iso8859-15 -t utf8 >>w
echo convert file to utf8
echo ================ Pgl Yoyo done ===========================
echo ================ Hosts File Go ===========================
wget -qnc -O - 'https://hosts-file.net/ad_servers.txt' | awk '/127.0.0.1/ {print $2}' | iconv -f iso8859-15 -t utf8 >>w
echo convert file to utf8
echo ================ Hosts File done ===========================
echo ================ dsfc Go ===========================
wget -qnc -O - 'https://www.dsfc.net/infrastructure/dns-infrastructure/unbound-redirecteur-cache-blacklist-dns/'|unhtml| tr -d '\<br/>'| tr -d '"' | awk '/local-zone/ {print $2}'| iconv -f iso8859-15 -t utf8 >>w
echo convert file to utf8
echo ================ dsfc done ===========================
echo remove tabulation character and carriage return
sed -i 's/\x0D$//' w
echo remove comments
sed -i 's/#//g' w
echo remove useless space
sed -i 's/ //g' w
echo remove empty lines
sed -i '/^\s*$/d' w
echo add prefix and suffix for unbound
echo "#" $(date +'%d-%m-%Y') >>adslist.txt
echo server: >>adslist.txt
cat w | sort -bdfu | awk '{print "local-zone: \""$1"\" redirect\nlocal-data: \""$1" A 127.0.0.1\""}' >adslist.txt
echo delete temporary file
rm -f w
echo download roots files
# wget -qnc -O /etc/unbound/root.hints ftp://ftp.internic.net/domain/named.cache
# wget -qnc -O root.hints ftp://ftp.internic.net/domain/named.cache
echo unbound restart
# systemctl restart unbound.service
exit 0
Reply to: