|
|
sybperl-l Archive
Up Prev Next
From: "Sabherwal, Balvinder (MBS)"
<Balvinder dot Sabherwal at mortgagefamily dot com>
Subject: CGI Question.
Date: Dec 19 2001 3:53PM
Guy's,
I have a perl script which takes 2 parameter as Server Name and Command to
be executed.
>From the command line this is run as
test.pl -S SYBASE_Server -C sp_who
How can this be called from the HTML page and send the output back to the
HTML page. I tryed creating the html form and the action for the form calls
this script. The problem is is dosen't gives the results back to the web
page.
The HTML and perl codes are included below.
Thanks.
Here is the HTML code:
Test for Perl Script
The perl script is as below:
#!c:/perl/bin/perl.exe
print "Content-type:text/html\n\n";
$USAGE = "Usage: test.pl [-h|-H] -S -C
";
## Initializations Steps
use Getopt::Std;
use Sybase::CTlib;
use CGI ':standard';
if (!getopts('S:C:hH')) {
print "$USAGE\n";
exit 1;
}
$server = $opt_S; ## Server name to connect
$cmd = $opt_C; ##Command to be executed
sub get_sa_password ()
{
$password = "web_user_ps";
chomp ($password);
}
get_sa_password();
$Srv=$opt_S;
$usr="web_user";
$pswd=$password;
## if none of the options are specified
if(!$opt_S && !$opt_C && !$opt_h && !$opt_H) {
die "$USAGE";
}
die "$USAGE" if $opt_H;
die "$USAGE" if $opt_h;
if($Srv eq undef){
die "***Error(1200):Server name required***\n$USAGE";
}
if(!($usr)){
die "***Error($Srv, 1201):Login User Name required ***\n $USAGE";
}
if(!($password)){
die "***Error($Srv, 1201): Can't get the password!!! Password is required
***\n";
}
$pwd=$opt_p;
$uid = 'DBA_Maint'; $pwd = $password; $srv = $server;
$dbhndl = Sybase::CTlib->ct_connect($uid, $pwd, $srv); ## Connect to the
server.
if ($opt_C)
{
if($cmd eq "")
{
print "Nothing to do..... No command given...Exiting !!!!! \n";
print "End of Results Sets\n";
exit 0;
}
else
{
print header;
print start_html('output for the executed command'),
print "Started Command on the server now.. \n";
$dbhndl->ct_sql(print "On the Server");
my $data = $dbhndl->ct_sql("$cmd");
print "Command executed \n";
print "in the for \n";
foreach my $row (@$data) {
foreach my $col (@$row) {
print "$col ";
}
print "\n";
}
exit 0;
}
}
#############################################
## SUBROUTINES
#############################################
sub msg_cb
{
my($layer, $origin, $severity, $number, $msg, $osmsg, $dbh) = @_;
printf fh "\nOpen Client Message: (In msg_cb)\n";
printf fh "Message number: LAYER = (%ld) ORIGIN = (%ld) ",
$layer, $origin;
printf fh "SEVERITY = (%ld) NUMBER = (%ld)\n",
$severity, $number;
printf fh "Message String: %s\n", $msg;
if (defined($osmsg))
{
printf fh "Operating System Error: %s\n", $osmsg;
}
CS_SUCCEED;
}
sub srv_cb
{
my($dbh, $number, $severity, $state, $line, $server,
$proc, $msg) = @_;
# If $dbh is defined, then you can set or check attributes
# in the callback, which can be tested in the main body
# of the code.
printf fh "\nServer message: (In srv_cb)\n";
printf fh "Message number: %ld, Severity %ld, ",
$number, $severity;
printf fh "State %ld, Line %ld\n", $state, $line;
if (defined($server))
{
printf fh "Server '%s'\n", $server;
}
if (defined($proc))
{
printf fh " Procedure '%s'\n", $proc;
}
printf fh "Message String: %s\n", $msg; CS_SUCCEED;
}
|