[BlueOnyx:15337] Re: Command line to list site aliases

Michael Stauber mstauber at blueonyx.it
Sat May 3 17:43:54 -05 2014


Hi Dan,

> I'm trying to automate a few tasks and need a list of all the web (and 
> email) aliases for a site.
> 
> I could do a `grep RewriteCond /etc/httpd/conf/vhosts/*` and spend ages 
> cleaning up the output but I figure the data is in CCE somewhere anyway.
> 
> I've used the output of `/usr/sbin/clistvsite` in the past which is a 
> perfect format except it not including the site aliases.
> 
> I guess I could use `cmuExport -c` and parse the XML output.
> 
> Has anyone done this before and has a good hack? :-)

Try this:

-------------------------------------------------------
#!/usr/bin/perl -I/usr/sausalito/perl
# $Id: findalias.pl, v1.0.0.0 Mi 21 Mai 2008 15:56:35 CEST mstauber Exp $
# Copyright 2008 Solarspeed Ltd. All rights reserved.
#
# Script to generate a list of all sites, their IP and which Email Server
# Aliasses and Web Server Aliasses they have.

use CCE;
my $cce = new CCE;

$cce->connectuds();

# Find /home in CCE
@oids = $cce->find('Vsite', '');
if ($#oids < 0) {
    print "Could not find any sites.\n";
}
else {
    $number = $#oids;
    $number++;
    print "Found $number sites.\n\n";
    foreach $result (@oids) {
        ($ok, $site) = $cce->get($result);
        print "----------------------------------------------------\n";
        print "Sitename: \t$site->{fqdn} - $site->{ipaddr}\n\n";
        @web = $cce->scalar_to_array($site->{webAliases});
        print "Web-Alias: \n";
        $web = 0;
        foreach $line (@web) {
            $web++;
            print "\t\t" . $line . "\n";
        }
        if ($web == "0") {
            print "\t\t-- n/a --\n";
        }
        print "\n";
        @mail = $cce->scalar_to_array($site->{mailAliases});
        print "Mail-Alias: \n";
        $mail = 0;
        foreach $line (@mail) {
            $mail++;
            print "\t\t" . $line . "\n";
        }
        if ($mail == "0") {
            print "\t\t-- n/a --\n";
        }
        print "\n";
    }
    print "--------------------------------------------------------\n";
}

$cce->bye();
exit 0;
-------------------------------------------------------

It walks through all sites and lists the Sitename (and IP), the
Web-Aliases and Email Server Aliases in a format similar to this:

----------------------------------------------------------------------------
Sitename:       www.aventurin.net - 208.77.221.199

Web-Alias:
                aventurin.net

Mail-Alias:
                aventurin.net

----------------------------------------------------------------------------


-- 
With best regards

Michael Stauber



More information about the Blueonyx mailing list