http://www.perlmonks.org?node_id=409653

Maddingue has asked for the wisdom of the Perl Monks concerning the following question:

Hello all, As I am trying to debug a quite hairy Sendmail problem, I'd like to read its virtuser.db (it's the DB for virtual users). Searching CPAN a module to read Berkeley databases, I found BerkeleyDB and wrote this little script:
#!/usr/bin/perl use BerkeleyDB; my $file = shift || die "usage: $0 file"; %hash = (); my $db = tie %hash, 'BerkeleyDB::Hash', -Filename => $file, -Flags => DB_RDONLY, -Property => DB_DUP | DB_DUPSORT or die "can't read file '$file': $!"; my $ref = $db->db_stat; print "db info: \n", map{" - ${_}: ".$ref->{$_}.$/} keys %$ref; print "db contains ", scalar(keys %hash), " entries\n"; print map { " $_ => $hash{$_}\n" } sort keys %hash;
The script fails at the tie() but with no error in $! Then I tried with DB_File, and wrote this script:
#!/usr/bin/perl use DB_File; my $file = shift || die "usage: $0 file"; %hash = (); tie %hash, 'DB_File', $file, O_RDONLY, 0666, DB_HASH or die "can't read file '$file': $!"; print "$file has ", scalar(keys %hash), " entries\n"; print map { " $_ => $hash{$_}\n" } sort keys %hash;
which also fails with the following error:
type parameter is not a reference at /usr/lib/perl5/5.6.1/i386-linux +/DB_File.pm line 262.
So.. my question is: if anyone has an experience with one of these modules, or with Sendmail .db files, or best, already has a script that dump the content of a Berkeley DB in human readable form, I'm all for it! (I know dbdump included with BerkeleyDB, but it does not dump the content in human readable form). Thanks in advance for anyone who has an idea