I don't use DBI to do this, but this will work, and is how I normally do the
database maintenance jobs on my databases.
open (logfile, ">e:/tasks/${date}-maint.txt") || die "$!";
# put other DB maint stuff here
# Use back-ticks to bring in the output of the command:
$str = `ISQL -Usa -P -Q"DBCC CHECKDB($dbname)"`;
print logfile $str."\n";
# finish the job
If you'd rather, that can be done with an ISQL script with output redirected
to a log file, and then use Perl to parse that (into another database is my
preference). I suppose that's up to you.
Steve H.
-----Original Message-----
From: Tobias Hausmann [mailto:[EMAIL PROTECTED]]
Sent: Monday, August 20, 2001 8:46 PM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: dbi and dbcc on WinNT 4.0
Hi,
Right now, I am working on a dbcc perl script for a Sybase database. I
have noticed that I get a different output with dbi (do(do checkdb ...))
than with isql. What can I do to get the same output with dbi as with
isql. I plan to use the output to check the database for any kind of
inconsistencies.
Any help would be highly appreciated.
Tobias Hausmann
# check database integrity
sub checkdbintegrity
{
my @searchlist = qw (Msg Level State error: corrupt);
my $sth1 = $dbh->prepare("select name from sysdatabases");
$sth1->execute();
while( my $dbname = $sth1->fetchrow_array)
{
$sth = $dbh->do("dbcc checkdb ($dbname)")
#process output
$dbh->errstr();
.....
}
}
________________________________________________________
isql output:
Checking master
Checking sysobjects
The total number of data pages in this table is 4.
Table has 64 data rows.
Checking sysindexes
The total number of data pages in this table is 7.
Table has 76 data rows.
Checking syscolumns
The total number of data pages in this table is 17.
__________________________________________________________________
dbi do(checkdb checkdb(db)) output:
Server message number=2536 severity=10 state=2 line=1 text=Checking
master
Server message number=2536 severity=10 state=3 line=1 text=Checking
sysobjects
Server message number=2579 severity=10 state=1 line=1 text=The total
number of d
ata pages in this table is 4.
Server message number=7929 severity=10 state=1 line=1 text=Table has 64
data row
s.