#!/usr/bin/perl -w # file KLEIDER/catalog/src/dbdump/dbname.pl # Name einer MariaDB-Datenbank anhand des DBKEY # 2020-12-10 Herbert Schiemann # GPL Version 2 oder neuer use Cwd qw(realpath); sub help { print <<"HELP"; dbdump/dbname.pl Name einer MariaDB-Datenbank anhand des DBKEY 2020-12-10 Herbert Schiemann dbname=\$($0 DBKEY) HELP exit 0; } help () if @ARGV != 1; my $dbkey = shift (@ARGV); help () if $dbkey eq "--version" or $dbkey eq "--help"; my $secrets = realpath($0); $secrets =~ s/\/catalog\/.*$//; $secrets = "$secrets/web/secrets"; my $hnd; if (! open ($hnd, "<:encoding(utf-8)", $secrets)) { print STDERR "Kann Datei \"$secrets\" nicht lesen:$!\n"; exit 1; } my $line; my $dbname; my $dbn; while (defined ($line = <$hnd>)) { $line =~ s/\s*$//; if ( $line =~ /^\s*dbkey.mysql.([a-z0-9]+)\s*=\s*(.+)/ ) { $dbname = $2 if ($1 eq $dbkey); } elsif ($line =~ /^\s*mysql\.([a-z0-9]+)\.name\s*=\s*(.+)/) { $dbn = $2 if ($dbname && $1 eq $dbname); } } close $hnd; $dbn ||= $dbname; if (!$dbn) { print STDERR "Datenbank nicht gefunden: dbkey $dbkey\n"; exit 1; } print $dbn; # end of file KLEIDER/catalog/src/dbdump/dbname.pl