2010-11-25

Perl one-liner: checking Listen ports on Apache HTTP configuration files.

You stumble upon an installation of Apache HTTP Server that has a few configuration files. You want to do a quick visual inspection of their Listen directives to check for conflicts.

This will also help you find if any Listens are duplicated within a single file. See port 443 in foo_httpd.conf.

jbm@Foucault:~/tmp/conf$ perl -mData::Dumper -ane '$f{$ARGV}->{$F[1]}++ if /^\s*Listen/; END { print Data::Dumper::Dumper(\%f);}' *conf
$VAR1 = {
'bar_httpd.conf' => {
'94' => 1,
'494' => 1
},
'admin.conf' => {
'8008' => 1
},
'blarf_httpd.conf' => {
'8011' => 1
},
'foo_httpd.conf' => {
'90' => 1,
'443' => 2,
'80' => 1,
'490' => 1
},
'httpd.conf' => {
'80' => 1
}
};

Yes, this is a long way to type a grep command, but I think the output lends itself more to visual inspection, which is what I'm after.

jbm@Foucault:~/tmp/conf$ egrep '^[[:space:]]*Listen' *conf
admin.conf:Listen 8008
bar_httpd.conf:Listen 494
bar_httpd.conf:Listen 94
blarf_httpd.conf:Listen 8011
foo_httpd.conf:Listen 90
foo_httpd.conf:Listen 443
foo_httpd.conf:Listen 80
foo_httpd.conf:Listen 490
foo_httpd.conf:Listen 443
httpd.conf:Listen 80

No comments:

Post a Comment