[sysadmin] vhostlist

On our public web server, we are hosting a
lot of stuff. Currently, we have over one hundred virtual hosts defined in
Apache.

One day, I realised that I didn’t have an overview any more of all these
deployments. That’s when I decided to write a simple script to produce me a
list of all virtual hosts (and aliases) in HTML. As it’s all about file
parsing, and I got a bit bored of Perl, I decided to write it in AWK and wrap
it in sh so it can be installed as a CGI script on the same web server.


#!/bin/sh

echo 'Content-Type: text/html; charset=iso-8859-1'
echo 'Cache-Control: no-cache'
echo 'Cache-Control: no-store'
echo 'Pragma: no-cache'
echo 'Expires: Thu, 01 Dec 1994 16:00:00 GMT'
echo

echo '< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">'
awk 'BEGIN {print "

Virtual Hosts configured on mars

    "} /^[ \t]*Server(Name|Alias)/ { $1=""; split($0, domains); for (i=0; i%s

    \n", domains[i+1], domains[i+1])}} END { print "

"}' /etc/apache2/vhosts.d/*

It’s still really basic, but it serves it’s purpose. Wished feature is to show
a difference between ServerName’s and ServerAlias’es. This is left as an
exercise to the reader.

Add a Comment   Trackback  

Add a Comment