Block Ads using dnsmasq

DNSMasq is a very light-weight DNS server that is perfectly suited to run on low power home appliances like NAS devices or routers running custom firmware.
The script below pulls ad blocking host files from 3 different providers and combines them to use as a DNSMasq resolver file.

Here is the script – it can be used verbatim on a Synology NAS running the DNSMasq package from http://syndnsmasq.the-ninth.com/.

Edit the DNSMasq file to add an entry ‘addn-hosts’ to point to the hosts file that was just created – for example:
addn-hosts=/root/AdBlock/adblock.uniq


#!/bin/sh
cd ~/AdBlock

echo "# Generated on: $(date +"%D %T")" > adblock

echo "Downloading file from YoYo.org"
wget -O yoyo http://pgl.yoyo.org/as/serverlist.php?hostformat=hosts&showintro=0
wait
echo "Processing YoYo.org file"
cat yoyo | grep "127.0.0.1" | awk '{ print "0.0.0.0\t"$2 }' >> adblock
wait

echo "Downloading file from SomeoneWhoCares.org"
wget -O swc http://someonewhocares.org/hosts/zero/
wait
echo "Processing SomeoneWhoCares.org file"
cat swc | grep "0.0.0.0" | awk '{ print "0.0.0.0\t"$2 }' | grep -v "#" >> adblock
wait

echo "Downloading file from MVPS.org"
wget -O mvps http://winhelp2002.mvps.org/hosts.txt
wait
echo "Processing MVPS.org file"
cat mvps | grep 0.0.0.0 | grep -v "# 0.0.0.0" | awk '{ print "0.0.0.0\t"$2 }' >> adblock
wait

echo "Downloading file from HPHosts"
wget -O hphosts http://hosts-file.net/download/hosts.txt
wait
echo "Processing HPHosts file"
cat hphosts | grep "127.0.0.1" | awk '{ print "0.0.0.0\t"$2 }' >> adblock
wait

echo "Writing changes to zone file"
tr '[A-Z]' '[a-z]' < adblock | sort -f | uniq > adblock.uniq
wait

echo "Reloading DNS Server"
/var/packages/dnsmasq/scripts/start-stop-status stop
/var/packages/dnsmasq/scripts/start-stop-status start
/var/packages/dnsmasq/scripts/start-stop-status status

Get complete ESX Host inventory from VCenter

This is a handy little script that gives you a complete list of all hosts and some pertinent information about them including Config Issues reported by VCenter.
The script saves all this information to a CSV file and emails the contents of that file in a formatted table to the email address you specify.
Let me know if there are other parameters that you think should be in here but aren’t and I will put them in here. Continue reading

Find space consumed by a Thin Provisioned vmdk

Here’s some fun commands to get some stats on Thin provisioned disks.

To find out the actual space consumed on disk (in GB):

stat <filename-flat>.vmdk | grep Size: | awk '{print (($4*512)/(1024*1024*1024))}'

To find out the total space provisioned (in GB):

stat <filename-flat>.vmdk | grep Size: | awk '{print ($2/(1024*1024*1024))}'

Percent not used:

stat <filename-flat>.vmdk | grep Size: | awk '{print ((($2/(1024*1024*1024))-($4*512)/(1024*1024*1024))/($2/(1024*1024*1024)))*100}'