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 peppler dot org>
Subject: Re: Sybperl in CGI...
Date: Sep 20 2000 4:59PM

Pantera, Joseph F. writes:
 > Sybperl Discussion Group:
 > 	Is there anyone out there who can help me with a quick tourn-around
 > in order to get some Sybperl scripts I've written displayed on an Apache
 > Server as a Perl / CGI?  Sorry to clutter the message board (you can tell me
 > to go elsewhere if you give me a recommended place to go) with an issue like
 > this.  I have not configured my Apache Server to run CGI scripts before.  I
 > have some Sybperl scripts that I modified to add basic HTML directives to
 > the output.  They work fine if I run the scripts as a perl executable on my
 > Apache Server / UNIX box, write to a file (say, sybperl_out.html in my
 > ServerRoot) and then display out of my brower at 
 > http:///sybperl_out.html .  It is not an issue with Sybperl,
 > since I cannot even get the canned "printenv" (print environment variables)
 > to run that automatically gets shipped in cgi-bin (yes, I made it
 > executable):
 > #!/bin/perl
 > ##
 > ##  printenv -- demo CGI program which just prints its environment
 > ##
 > print "Content-type: text/plain\n\n";
 > foreach $var (sort(keys(%ENV))) {
 >     $val = $ENV{$var};
 >     $val =~ s|\n|\\n|g;
 >     $val =~ s|"|\\"|g;
 >     print "${var}=\"${val}\"\n";
 > }
 >  I have modified the Apache httpd.conf file with a ScriptAlias to point to
 > the location of the scripts, but nothing is displaying (in output) if I add
 > a directive in my HTML with a call like:
 > We're now going to execute /opt/apache/cgi-bin/printenv:
 > <<  >>
 > But the ouptput looks like this:
 > We're now going to execute /opt/apache/cgi-bin/printenv: << >>
 > It is probably something missing from my httpd.conf, but I've been
 > scrambling around several different resources and nothing seems to work.
 > Needing to display this in browser format, since current scripts only
 > running on HP-UX, and my Windows users who need to run them are shuddering
 > at the prospects of telneting into a UNIX box to run them.

First off it looks like you want to execute the scripts as server-side 
includes, instead of simply executing them in directly. The difference 
would be to have the user type something like


(or whatever the script name is) and have the script then handle all
the html output. This is simpler (I think) and should normally work
with the default Apache config. I've got:

# ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the realname directory are treated as applications and
# run by the server when requested rather than as documents sent to the client.
# The same rules about trailing "/" apply to ScriptAlias directives as to
# Alias.
ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"

# "/usr/local/apache/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.

    AllowOverride None
    Options ExecCGI
    Order allow,deny
    Allow from all

(I've also got some modperl stuff later in the httpd.conf, but that's
irrelevant here).

If you want server-side includes to work you have to add the +Includes 
option to the main htdocs directory (or to the directory where the
.html files that include the  calls reside, like so:

    Options Indexes FollowSymLinks +Includes
    AllowOverride None
    Order allow,deny
    Allow from all

Now you need to see the AddHandler statements in the httpd.conf:

# To use server-parsed HTML files
AddType text/html .html
AddHandler server-parsed .html

SSI (server-side includes) should now work.

However, like I said, you're probably better off writing CGI scripts
that do the whole thing, like this, for example:

#!/usr/local/bin/perl -w

use strict;
use Sybase::CTlib;
use CGI;

my $dbh = new Sybase::CTlib 'sa', '', 'SYBASE';
my $q = new CGI;

print $q->header(-Refresh => '60; URL=' . $q->self_url);
print $q->start_html;

print "\n";

my $restype;
$dbh->ct_execute('select * from sysprocesses');
while($dbh->ct_results($restype) == CS_SUCCEED) {
    next unless $dbh->ct_fetchable($restype);
    my @cols = $dbh->ct_col_names;
    print "\n";
    foreach (@cols) {
	print "\n";
    print "\n";
    my @data;
    while(@data = $dbh->ct_fetch) {
	print "\n";
	foreach (@data) {
	    $_ = 'NULL' unless $_;
	    print "\n";
	print "\n";

print "
"; print $q->end_html; __END__ which prints out the contents of the master..sysprocesses table every minute... Michael -- Michael Peppler -||- Data Migrations Inc. -||- Int. Sybase User Group -||- Sybase on Linux mailing list: