Michael Peppler
Sybase Consulting
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
Sybase on Linux FAQ
Sybperl FAQ
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Michael Peppler <mpeppler at MBAY dot NET>
Subject: Problem executing dbcc with CTLib
Date: Feb 26 1999 3:08PM

Dan Johansson writes:
 > Hi SybPerlers,
 > I'm trying to execut a dbcc comand with CTLib.
 > The problem I'm having is that I'm not able to capture the output from the
 > dbcc comand, so am not sure if the command executes or not.

The output goes to the server callback (via PRINT statements).

Here's a CTlib script that should work:


#	@(#)	1.1	12/30/97

use Sybase::CTlib;
require '';
require '';

# options: -d database -P sa_password -S server -m mail-to

$opt_m = 'sybase' unless($opt_m); # send mail to 'sybase' if no other specified

$dbh = new Sybase::CTlib 'sa', $opt_P, $opt_S;

ct_callback(CS_SERVERMSG_CB, \&msg_hdl); 

die "$0: -d database_name not specified!\n" if(!defined($opt_d));
$db = $opt_d;
$logfile = "/var/tmp/$db.dbcc";
$tmpfile = "/tmp/dbcc$$";

open(LOG, ">$logfile") || die "Can't open log file $logfile: $!\n";
open(TMP, ">$tmpfile") || die "Can't open file $tmpfile: $!\n";

&dolog(" for $db started at ", scalar(localtime), "\n");
&dolog("***** checkdb($db) *****\n");
&dbexec("dbcc checkdb('$db')\n");
&dolog("***** checkalloc($db) *****\n");
&dbexec("dbcc checkalloc('$db')\n");
&dolog("***** checkcatalog($db) *****\n");
&dbexec("dbcc checkcatalog('$db')\n");
&dolog(" for $db done at ", scalar(localtime), "\n");


system("/usr/ucb/Mail -s 'DBCC $db' $opt_m <$tmpfile");

sub dbexec {
    my($cmd) = @_;
    my(@dat, $ret);

#    $dbh->ct_cmd_realloc;
    while($dbh->ct_results($ret) == CS_SUCCEED) {
	next unless $dbh->ct_fetchable($ret);
	while(@dat = $dbh->ct_fetch) {
	    print "@dat\n";

sub dolog {
    my(@strings) =@_;

    print LOG @strings;
    print TMP @strings;

sub msg_hdl
    my($cmd, $number, $severity, $state, $line, $server, $proc, $text)
	= @_;

    if ($severity > 10)
	print TMP ("Sybase message ", $number, ", Severity ", $severity,
	       ", state ", $state);
	print TMP ("\nServer `", $server, "'") if defined ($server);
	print TMP ("\n    ", $text, "\n\n");
    elsif ($number == 0)
	print STDERR ($text, "\n");
    printf LOG ("%4d %d %d $text", $number, $state, $severity)
	if($number != 0);
Michael Peppler         -||-  Data Migrations Inc.       -||-
Int. Sybase User Group  -||-
Sybase on Linux mailing list: