Hallo,
ich verwende /etc/hosts zum blockieren von Werbung und anderem Mist. Da es etwas mühsam ist, die Datei manuell zu pflegen, habe ich die Aufgabe an ein Script delegiert.
Das klappte bis vor Kurzem auch recht gut, nun produziert das Script allerdings nur noch eine (bis auf den korrekten Header) leere hosts-Datei, die Daten werden zwar korrekt heruntergeladen, aber nicht übernommen.
Hier mal das Script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | #!/bin/bash # if [ `whoami` != "root" ]; then echo "Insufficient permissions. Run as root." exit 0 fi HOSTSDIR="/etc/hosts.d/" TMPDIR="${HOSTSDIR}tmp/" OUTPUTFILE="/etc/hosts" if [ ! -d "${TMPDIR}" ]; then mkdir -p ${TMPDIR} fi if [ ! -f "${HOSTSDIR}hosts.local" ]; then echo "You need to create "${HOSTSDIR}hosts.local" containing the hosts you wish to keep!" echo -e "fe00::0 ip6-localnet" > "${HOSTSDIR}hosts.local" echo -e "ff00::0 ip6-mcastprefix" >> "${HOSTSDIR}hosts.local" echo -e "ff02::1 ip6-allnodes" >> "${HOSTSDIR}hosts.local" echo -e "ff02::2 ip6-allrouters" >> "${HOSTSDIR}hosts.local" echo -e "ff02::3 ip6-allhosts" >> "${HOSTSDIR}hosts.local" fi if [ ! -f "${HOSTSDIR}hosts.whitelist" ]; then echo "You need to create "${HOSTSDIR}hosts.whitelist" containing the hosts you want to discard from the lists!" echo -e "#" > "${HOSTSDIR}hosts.whitelist" fi echo Downloading hosts.hphosts... curl --compressed -v -# -o "${TMPDIR}hosts.hphosts" "http://hosts-file.net/download/hosts.txt" echo Downloading hosts.adservers... curl --compressed -v -# -o "${TMPDIR}hosts.adservers" "http://hosts-file.net/ad_servers.asp" echo Downloading hosts.partial... curl --compressed -v -# -o "${TMPDIR}hosts.partial" "http://hosts-file.net/hphosts-partial.asp" echo Downloading hosts.mvps... curl --compressed -v -# -o "${TMPDIR}hosts.mvps" "http://winhelp2002.mvps.org/hosts.txt" echo Downloading hosts.minenu... curl --compressed -v -# -o "${TMPDIR}hosts.minenu" "http://hostsfile.mine.nu/Hosts" echo Downloading hosts.malware... curl --compressed -v -# -o "${TMPDIR}hosts.malware" "http://www.malwaredomainlist.com/hostslist/hosts.txt" echo Downloading hosts.sowc... curl --compressed -v -# -o "${TMPDIR}hosts.sowc" "http://someonewhocares.org/hosts/hosts" echo Downloading hosts.ismeh... curl --compressed -v -# -o "${TMPDIR}hosts.ismeh" "http://www.ismeh.com/HOSTS" echo Downloading hosts.securemecca... curl --compressed -v -# -o "${TMPDIR}hosts.securemecca" "http://www.securemecca.com/Downloads/hosts.txt" echo Downloading hosts.yoyo... curl --compressed -v -# -o "${TMPDIR}hosts.yoyo" "http://pgl.yoyo.org/as/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext" # hosts header cat "${HOSTSDIR}hosts.local" > "${OUTPUTFILE}" cat "${TMPDIR}hosts.hphosts" \ "${TMPDIR}hosts.adservers" \ "${TMPDIR}hosts.partial" \ "${TMPDIR}hosts.mvps" \ "${TMPDIR}hosts.minenu" \ "${TMPDIR}hosts.malware" \ "${TMPDIR}hosts.sowc" \ "${TMPDIR}hosts.ismeh" \ "${TMPDIR}hosts.securemecca" \ "${TMPDIR}hosts.yoyo" | \ sed -e 's/ / /g' | \ grep -e '127.0.0.1 ' | \ tr -d "\r" | \ tr -s [:space:] | \ cut -d " " -f -2 | \ sort | uniq | \ grep -vf "${HOSTSDIR}hosts.whitelist" | \ sed -e 's/127.0.0.1 /0.0.0.0 /g' >> "${OUTPUTFILE}" echo -e "Done!" |
Möglicherweise sieht ja Jemand den Fehler, ich konnte soweit Keinen erkennen.