PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: tscheresky <tscheresky at micron dot com>
Subject: RE: Sybping...
Date: Aug 9 2000 9:29PM

Michael that was exactly what I was looking for.  Thank you!

Here's my interpretation of what you sent me.  I tweaked mine to accept
multiple Sybase Servers:

use strict;
use Sybase::CTlib;

( @ARGV ) || die "Usage: sybping.pl  [  ... ]\n";

my $gError;

sub handler
{
  $gError .= join(' ', @_);

  CS_SUCCEED;
}

ct_callback ( CS_CLIENTMSG_CB,\&handler );
ct_callback ( CS_SERVERMSG_CB,\&handler );

foreach (@ARGV)
{
  $gError = '';

  my $dbh = new Sybase::CTlib( 'sa','dabadoo!',$_ );

  if ( $dbh || $gError =~ /4002|4067/)
  {
    print "The server $_ is up.\n";
  }
  else
  {
    print "Can't reach $_: $gError\n";
  }
}

-----Original Message-----
From: Michael Peppler [mailto:mpeppler@peppler.org]
Sent: Wednesday, August 09, 2000 12:31 PM
To: SybPerl Discussion List
Subject: Re: Sybping...


tscheresky writes:
 > Sybase provides a utility called sybping on Windows that tells me whether
a
 > particular Sybase Server is available.  How would I emulate the same
 > functionality using Perl and Sybperl, either through CTlib or DBlib?

Something like this:

#!/usr/local/bin/perl
use Sybase::CTlib;

$error = '';

sub handler {
    $error .= join(' ', @_);

    CS_SUCCEED;
}

ct_callback(CS_CLIENTMSG_CB, \&handler);
ct_callback(CS_SERVERMSG_CB, \&handler);

$dbh = new Sybase::CTlib 'sa', 'dabadoo!', $the_server;
if($dbh || $error =~ /4002|4067/) {
    print "The server $the_server is up\n";
} else {
    print "Can't reach $the_server: $error\n";
}

Examples:

1> perl ~/tmp/sybping.pl coconut
Can't reach coconut: 5 3 5 4 ct_connect(): network packet layer: internal
net library error: Net-Lib protocol driver call to connect two endpoints
failed Socket connect failed - errno 111 
2> perl ~/tmp/sybping.pl xyz    
Can't reach xyz: 5 3 4 3 ct_connect(): network packet layer: internal net
library error: Specified server name attribute could not be found  
3> perl ~/tmp/sybping.pl kiruna 
The server kiruna is up

The 4067 error number above is what ASE 12.0 and later respond with if 
the password is invalid.

Michael
-- 
Michael Peppler         -||-  Data Migrations Inc.
mpeppler@peppler.org    -||-  http://www.mbay.net/~mpeppler
Int. Sybase User Group  -||-  http://www.isug.com
Sybase on Linux mailing list: ase-linux-list@isug.com