#!/usr/bin/perl

use lib '/app/tools/common/lib';
use Common::RSDB;

my @dbs = _getAllDatabaseNames();
my $allInAString = join( ' ', @dbs );
print "$allInAString\n";

sub _getAllDatabaseNames {

    # First, query mysql to get the list of dbs.
    #

    my $dbsRaw = `/usr/bin/mysqlshow -uroot`;

    # Doesn't seem to be a way to get a simple list - so we have to parse the
    # names out from all the extra display frosting this command returns.
    #

    my @dbNames;
    my @lines = split( "\n", $dbsRaw );

    for ( my $i = 0 ; $i < ( scalar @lines ) - 1 ; $i++ ) {

        # First three lines are crap.
        #
        next if $i < 3;

        if ( $lines[$i] =~ m/\| (\S*) (.*)\|/ ) {
            my $name = $1;
            if ( 'C_' eq substr( $name, 0, 2 ) ) {
                my $id = Common::RSDB::DBNameToClientID($name);
                push @dbNames, $id;
            }
        }
    }

    return @dbNames;
}

