Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Question about HTML and Perl

by CG_man (Novice)
on Nov 06, 2008 at 03:06 UTC ( [id://721888]=perlquestion: print w/replies, xml ) Need Help??

CG_man has asked for the wisdom of the Perl Monks concerning the following question:

I am new to HTML and Perl, but I'm automating a process for my company. I'm using HTML, and I have a perl script on a unix machine that queries a SQL database. The thing is when I run the perl script from the command line on the unix machine, the output is what I want. I have an HTML page that I have created and everything is all set, the 1 missing piece is getting the HTML page to 1. execute the perl script, 2, display the output of the script on the HTML page. I'm not sure of the source code or what else I need. Below is the html page, Note where "NA" is, is where I need the output to be placed in the table. Any suggestions to what the code should be, I've googled for results and have came up empty ? In short, how to I code the HTML page to execute the perl script which is on the unix box and print the data on the html page?
<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</TD> <TD><LI><A HREF='/cgi-bin/autorep_de +v_vsl.pl?job_name=dh_box_settle&level=detail'>dh_box_settle</A> </TD> + <TD>NA</TD>

Replies are listed 'Best First'.
Re: Question about HTML and Perl
by GrandFather (Saint) on Nov 06, 2008 at 03:19 UTC
Re: Question about HTML and Perl
by mpeever (Friar) on Nov 06, 2008 at 06:16 UTC

    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.

Re: Question about HTML and Perl
by Gangabass (Vicar) on Nov 06, 2008 at 03:15 UTC

    Well, it's better to show us relevant pieces of your script...

Re: Question about HTML and Perl
by eighty-one (Curate) on Nov 06, 2008 at 13:45 UTC

    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.

Re: Question about HTML and Perl
by lorn (Monk) on Nov 06, 2008 at 10:48 UTC

    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

      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

        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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://721888]
Approved by Lawliet
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-25 11:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found