I am working on a script to collect system information, and I have
run into a problem I cannot quite figure out. Here is the pertinent section
of code:
my $test = $dbh->prepare("SELECT id FROM fsref WHERE server ='$server' AND
fs_
name = '$fs_name'");
$test->execute ();
$rows = $test->rows;
print "Server name: $server Filesystem: $fs_name \n";
print "Number of matching rows: $rows \n";
if ($rows == 1) {
my $vals = $test->fetchrow_hashref ('NAME_lc');
my $id = $vals->{id};
my $query = $dbh->prepare("SELECT * FROM fsdata WHERE id ='$id'");
$query->execute ();
while (my $ref = $query->fetchrow_hashref ('NAME_lc')) {
undef $set;
foreach my $key (keys %$ref) {
unless ($$key eq $ref->{$key}) {
$set .= " , " if $set;
$set .= $key . "=\'$$key\'";
}
}
if ($set) {
print "Entry found in database. Updating information for $id. \n";
my $sql = "UPDATE fsdata SET $set WHERE id = '$id'";
my $sth = $dbh->prepare(qq{$sql});
$sth->execute;
}
}
} else {
$dbh->do("INSERT INTO fsref VALUES('$id','$server','$fs_name')") or
print "E
rror updating fsref table: ", $dbh->errstr, "\n";
$id = $dbh->{mysql_insertid};
$dbh->do("INSERT INTO fsdata
VALUES('$id','$lvol','$stripe_num','$stripe_siz
e','$size','$owner','$group','$export')") or print "Error updating fsdata
table:
", $dbh->errstr, "\n";
print "Entry not found in database. Adding information for $id. \n";
}
}
The code before this appears to be functioning properly, and is the
actual data collection commands i.e. bdf, vgdisplay, etc. The problem is
that I am getting some error messages that I do not understand what is
causing them. Any help would be greatly appreciated. Here is a portion of
the output errors.
Server name: stanley Filesystem: /var
Number of matching rows: 1
Use of uninitialized value in string eq at ./space_data.pl line 53.
Use of uninitialized value in concatenation (.) at ./space_data.pl line 55.
Entry found in database. Updating information for 23.
DBD::mysql::st execute failed: Duplicate entry '0' for key 1 at
./space_data.pl
line 62.
Note: The first line of the included code is line 39. Thanks.
Scott Nipp
Phone: (214) 858-1289
E-mail: [EMAIL PROTECTED]
Web: http:\\ldsa.sbcld.sbc.com