Archive for the ‘Command Line Kung Fu’ Category

Bind Logs – Top DNS Queries

By Mark Davidson on September 3rd, 2010

This week at work we fancied figuring out what the top sites are on are network. So decided an easy way to work this out would be to enable logging on are bind server and then write a script to work out what the top DNS queries are.
Read & Comment ›››

Get Unique Hostnames from Apache Config Files

By Mark Davidson on April 8th, 2010

Currently where I work we are in progress of doing a big server move and we wanted to get a list of all the domains currently running on one of the servers. So I wrote this bit of Command Line Kung Fu to do just that. Thought that it was quite cool and handy so decided to share it.

So if you run the following (This is with a default Ubuntu configuration of Apache might need to change the path if your configuration is different)

cat /etc/apache2/sites-enabled/* | egrep 'ServerAlias|ServerName' | tr -s " " | sed 's/^[ ]//g' | uniq | cut -d ' ' -f 2 | sed 's/www.//g' | sort | uniq

You will get output like this

Linux Find and Modification Time

By Mark Davidson on February 5th, 2010

Recently I needed to do some cleaning up of some temporary files on one of my web servers so I came up with this find command

find . -mtime +1 -type f -printf '%p %Ax\n'

this command will list files in the current directory that where last modified more than 24 hours ago, when printing out the file names it will also print out the date the file was last modified.

find . -mtime +1 -type f -printf '%AY-%Am-%Ad %AT %p\n' | sort

makes use of some more conditions within the printf and the sort command. By putting the date on the front of each entry which is printed out and using the sort command the files are printed in chronological order.

find . -mtime +0 -type f -print0 | xargs -0 du -csh

is the final example I will give this time which combines using find with xargs and du in order to find the disk usage of all the files that match the find condition.