So are you wanting the perl script to execute and put the output into the page that called it?
I'm having a little trouble understanding exactly what you're asking. You seem to be thinking of this in terms of embedded code, like PHP or JSP.
| [reply] |
Well, it's better to show us relevant pieces of your script...
| [reply] |
You say your Perl script works and you want to embedd it's output in an HTML document. What might be a simpler and easier to set up approach would be to have the script write the HTML document. Then you access the script via CGI, as explained in the links posted above by GrandFather.
So the script builds an HTML document and sends it's output to the browser, and the browser renders it as it would any other document.
There are ways you can embed Perl code within your document, and have the document be parsed as it's sent to the browser so that the code gets executed and replaced by it's own output. But I think it might be easier to start with CGI - when I was new to Perl I remember setting up CGI was fast and easy, but I don't know how difficult other approaches might be to a new Perl programmer, as I never tried when I was one.
Actually, there was a book I had for a class that I think had a good explanation of CGI and setting up a simple dynamic web page with Perl - but all I can remember is that it had a yellow and black cover. From scanning the pictures at Google shopping, I think it might have been Beginning Perl.
| [reply] |
Like the others, i think that i did not understand what did you want, but some tips:
- Did your scripts works in comand line? they put the right information in STDOUT?
perl autorep_dev_vsl.pl ( you need to get the params with @ARGS instead of cgi param )
- Check the error_log of apache maybe they can answer your questions
| [reply] [d/l] |
Thanks to all for your replies, and yes, the perl script work the way I want it to from the command line using bl -g
yes, I want to execute a perl script from the html page and have it post it's information into the html page. Most web reporting tools we use are built in CGI. However, I'm not to familiar with it. Most of our webtools start with HTML, then calls a cgi perl script, then that perl script calls for a script that queries the SQL database using bl -g.
As for what I am trying to accomplish, I'll try to be exact and give my html source code and perl script.
We have jobs that run, I'm using the perl script to query the database to extract just the end time of a job and place it in the "NA" section of the html table. I am not sure if HTML can do this, if not I will have to use CGI, but I want to keep with one web page, the HTML, if all possible.
See below the HTML file called prodcyctest.html the perl script I'm trying to run is called dndhtest2pa.pl, the other pl script in the href is working fine. I need the new perl script to embed it's data where the "NA" is in the table.
<HTML>
<BODY BGCOLOR='white'"
TEXT=BLACK
LINK=BLUE
VLINK=PURPLE
ALINK=RED
>
<META HTTP-EQUIV="REFRESH" CONTENT="30">
<HEAD>
<TITLE>Production Cycle Report Automated Test</TITLE>
</HEAD>
<BODY>
<STYLE TYPE="text/css">
<!--
H1
{
color:blue;
font-style:italic;
}
-->
</STYLE>
<H1>
<center>CG Production Cycle Report - TEST</H1>
<SCRIPT TYPE="text/javascript">
<!-- Begin
// Get today's current date.
var now = new Date();
// Array list of days.
var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday
+','Friday','Saturday');
// Array list of months.
var months = new Array('January','February','March','April','May','Jun
+e','July','August','September','October','November','December');
// Calculate the number of the current day in the week.
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();
// Calculate four digit year.
function fourdigits(number) {
return (number < 1000) ? number + 1900 : number;
}
// Join it all together
today = days[now.getDay()] + ", " +
months[now.getMonth()] + " " +
date + ", " +
(fourdigits(now.getYear())) ;
// Print out the data.
document.write(today);
// End -->
</script>
<SCRIPT Language="JavaScript">
<!-- hide from old browsers
// Copyright 1999, 2000 by Ray Stott
// OK to use if this copyright is included
// Script available at http://www.crays.com/jsc
var TimezoneOffset = -8 // adjust for time zone
var localTime = new Date()
var ms = localTime.getTime()
+ (localTime.getTimezoneOffset() * 60000)
+ TimezoneOffset * 3600000
var time = new Date(ms)
var hour = time.getHours()
var minute = time.getMinutes()
var second = time.getSeconds()
var curTime = "" + ((hour > 12) ? hour - 12 : hour)
if(hour==0) curTime = "12"
curTime += ((minute < 10) ? ":0" : ":") + minute
curTime += ((second < 10) ? ":0" : ":") + second
curTime += (hour >= 12) ? " PM" : " AM"
document.write(curTime + " US Pacific Time")
//-->
</SCRIPT>
<TABLE BORDER=2 CELLSPACING=6>
<TR> <TH>Key Milestones</TH> <TH>Job Name</TH> <TH>Completed T
+ime in PST</TH> <TH>SLA</TH> </TR>
<TR> <TD>Transaction Handoff PA to MARS CGTC/CII</TD> <TD><LI><A HREF=
+'/cgi-bin/autorep_dev_vsl.pl?job_name=pa_box_settle&level=detail'>pa_
+box_settle</A> </TD> <TD>NA</TD> <TD>8:45pm</TD> </TR>
<TR> <TD>Transaction Handoff PA2 to MARS CRMC</TD> <TD><LI><A HREF=
+'/cgi-bin/autorep_dev_vsl.pl?job_name=pa2_box_settle&level=detail'>pa
+2_box_settle</A> </TD> <TD>NA</TD> <TD>8:30pm</TD> </TR>
<TR> <TD>Transaction Handoff PA3 to MARS</TD> <TD><LI><A HREF=
+'/cgi-bin/autorep_dev_vsl.pl?job_name=pa3_box_settle&level=detail'>pa
+3_box_settle</A> </TD> <TD>NA</TD> <TD>8:30pm</TD> </TR>
</TABLE>
<STYLE TYPE="text/css">
<!--
H2
{
color:blue;
font-size:10pt;
}
-->
</STYLE>
<H2>
<center>Click on job name to view job information</H2>
</BODY>
</HTML>
Here is the perl script, it's setup to return Jobname, Last Start and End Time, but I have commented that out and just want the end time, again, the script works fine from the command line.
#!/users/contrib/bin/perl
use Sybase::Sybperl;
use Env qw(BATCH_USER_NAME BATCH_PASSWORD);
##############
############## Subroutines
##############
# Send the input string to the DB server and get the results
# $_[0] - sql string
sub DBEXEC {
&dbcmd($dbproc, $_[0]);
&dbsqlexec($dbproc);
&dbresults($dbproc);
}
# Turn UTC in to people time
sub GETTIME {
if ($_[0] eq "999999999") {
$time = ("******** **********");
}
elsif ($_[0] eq "0") {
$time = ("******** **********");
}
else {
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(
+$_[0]);
$mon++;
$time = sprintf ("%.2d:%.2d:%.2d %.2d/%.2d/%.2d", $hour, $min, $se
+c, $mon, $mday, $year + 1900);
}
}
# set job status
sub JOBSTATUS {
if ($_[0] == 9) {$jstatus1 = ("ACTIVATED");}
elsif ($_[0] == 5) {$jstatus2 = ("FAILURE");}
elsif ($_[0] == 8) {$jstatus3 = ("INACTIVE");}
elsif ($_[0] == 11) {$jstatus4 = ("ON_HOLD");}
elsif ($_[0] == 7) {$jstatus5 = ("ON_ICE");}
elsif ($_[0] == 12) {$jstatus5 = ("QUE_WAIT");}
elsif ($_[0] == 10) {$jstatus6 = ("RESTART");}
elsif ($_[0] == 1) {$jstatus7 = ("RUNNING");}
elsif ($_[0] == 3) {$jstatus8 = ("STARTING");}
elsif ($_[0] == 4) {$jstatus9 = ("SUCCESS");}
elsif ($_[0] == 6) {$jstatus10 = ("TERMINATED");}
}
############ Setup report format
############
format STDOUT =
@<<<<<<<<<<<<<<<<<<<<<
$etime
.
############
############ Start
############
# if ($ARGV[0] eq "print") {
# open(STDOUT,"| lp -dbigtooth -o2");
# }
# else {
# open(STDOUT,"| elm -s 'Nightly cycle check' \xxxxxxxx\@smtplink");
# }
# login to the database
$dbproc = &dblogin($BATCH_USER_NAME, $BATCH_PASSWORD, 'SQL_AUTOSYS_DEV
+');
#$currdate = &GETTIME(time);
#print "Date: $currdate \n\n";
#print " \n";
#print "Jobname Last Start Last End
+ \n";
#print "------------------------------ -------------------- ----------
+----------\n";
# Submit SQL Statement
&DBEXEC("select job.job_name, job_status.last_start, job_status.la
+st_end from job, job_status
where job.joid = job_status.joid and job.job_name in
('pa_box_settle')
order by job_status.last_end");
while(@status = &dbnextrow($dbproc)){
$name = ($status[0]);
$stime = &GETTIME($status[1]);
$etime = &GETTIME($status[2]);
write(STDOUT);}
#print "\n\n";
print " \n";
close(STDOUT);
Again, thanks, just learning, and wondering if HTML can even do what I'm trying to make it do with the perl script | [reply] [d/l] [select] |
Seconding and possibly expanding a bit on Grandfather's note, above, you clearly need to get a basic understanding of the relationship between Perl and CGIs (which may or may not be written in Perl).
May I recommend the slightly-dated but still-sound "Official Guide to Programming with CGI.pm" or, as a second choice, "CGI Programming with Perl".
May I also suggest you acquire a better understanding of HTML standards (and perhaps CSS), as the .html above is shot full of outdated or flatly "wrong" code. CF the double quote after the closing single quote in <BODY BGCOLOR='white'"... and the lack of quoting for the values of TEXT, LINK etcetera. There's no shortage of good instruction available on the web or on paper, some of the best of which can be found at w3schools.
| [reply] [d/l] [select] |