Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ksh to perl??

Status
Not open for further replies.

adamf

Technical User
Mar 7, 2002
51
GB
Hi,

Could anyone convert this script to perl for me... Having dome real problems getting it to run through apache as a shell script...

Code:
#!/bin/ksh

#
#       Simple script to run CheckProgressLog to HTML
#
WEBPAGE="/users/web/docs/adamlog.html"

function HEADER {
echo &quot;<html>

<head>
<meta http-equiv=\&quot;Content-Type\&quot;
content=\&quot;text/html; charset=iso-8859-1\&quot;>
<meta name=\&quot;GENERATOR\&quot; content=\&quot;Script generated by $PROC\&quot;>
<title>Extract from /var/log/progress.log</title>
</head>

<body bgcolor=\&quot;#FFFFFF\&quot;>
<table border=\&quot;0\&quot; cellpadding=\&quot;3\&quot;>
<tr><td width=\&quot;25%\&quot;>
<IMG BORDER=0 SRC=\&quot;/images/ctlogo.jpg\&quot; WIDTH=99 HEIGHT=33 ALT=\&quot;ux-gbbri-mk1\&quot;>
</td>
<TD WIDTH=\&quot;75%\&quot;><CENTER>
<H1>Extract from /var/log/progress.log</H1></CENTER></TD>
</tr></TABLE>
<table border=\&quot;0\&quot; cellpadding=\&quot;3\&quot;>
    <tr>
        <td><b>Hostname:</b></td>
        <td>`uname -n`</td>
    </tr>
</table>

<HR>
<FONT SIZE=\&quot;4\&quot;>
The following data is an extract of the last 100 lines of the 
/var/log/progress.log . This report<BR>
is printed in reverse order with the youngest entry at the top 
and oldest at the bottom.
<PRE>
<FONT SIZE=\&quot;2\&quot;>&quot;
}

function TRAILER {
echo &quot;
</PRE>
<HR>
<P ALIGN=\&quot;CENTER\&quot;>
<A HREF=\&quot;./additional_reports.html\&quot;>BACK</A>
</P>
Last Updated at `date`
</body>
</html>
&quot; 
}


exec > $WEBPAGE

HEADER
/usr/local/apache/cgi-bin/log_print.ksh -L
TRAILER

Thanks in advance!! Adam F
Solaris System Administrator
 
#!/usr/bin/local/perl -w
# i dont know much on ksh
# but it look as u need something like
use strict;

my $webpage = &quot;&quot;/users/web/docs/adamlog.html&quot;;

&readfile;
&makeheader;
foreach (@datastorer) {print &quot;$_<br>&quot;;}
&makemaketrailer;
&endofscript;


sub readfile {
open (FILE, $webpage&quot;) || die endofscript($!);
my @datastorer = <FILE>;
close (FILE) || die endofscript($!);
}

sub makeheader {
print &quot;Content-type: text/html\n\n&quot;;
print &quot;<html>
<head>
<meta http-equiv=\&quot;Content-Type\&quot;
content=\&quot;text/html; charset=iso-8859-1\&quot;>
<meta name=\&quot;GENERATOR\&quot; content=\&quot;Script generated by $0\&quot;>
<title>Extract from /var/log/progress.log</title>
</head>
<body bgcolor=\&quot;#FFFFFF\&quot;>
<table border=\&quot;0\&quot; cellpadding=\&quot;3\&quot;>
<tr><td width=\&quot;25%\&quot;>
<IMG BORDER=0 SRC=\&quot;/images/ctlogo.jpg\&quot; WIDTH=99 HEIGHT=33 ALT=\&quot;ux-gbbri-mk1\&quot;>
</td>
<TD WIDTH=\&quot;75%\&quot;><CENTER>
<H1>Extract from /var/log/progress.log</H1></CENTER></TD>
</tr></TABLE>
<table border=\&quot;0\&quot; cellpadding=\&quot;3\&quot;>
<tr>
<td><b>Hostname:</b></td>
<td>`uname -n`</td>
</tr>
</table>
<HR>
<FONT SIZE=\&quot;4\&quot;>
The following data is an extract of the last 100 lines of the
/var/log/progress.log . This report<BR>
is printed in reverse order with the youngest entry at the top
and oldest at the bottom.
<PRE>
<FONT SIZE=\&quot;2\&quot;>&quot;;
}

sub maketrailer {
print &quot;</PRE>
<HR>
<P ALIGN=\&quot;CENTER\&quot;>
<A HREF=\&quot;./additional_reports.html\&quot;>BACK</A>
</P>
Last Updated at `date`
</body>
</html>&quot;;
}

sub endofscript {
if ($_[0]) {
print &quot;Content-type: text/html\n\n<html>DEAD : $_[0]&quot;;
}
exit;
}

#
# hope this help u ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
Hi... Looks good, but when I tried to run it, it was fill of holes!

I am pretty clueless when it comes to Perl, so don't have a chance of debugging it myself...

If you get a chance, could you run thru it again & see if you can spot any problems? Here is a dump of the errors...

Code:
String found where operator expected at /usr/local/apache/cgi-bin/Log2HTML.pl line 23, near &quot;print &quot;&quot;
  (Might be a runaway multi-line &quot;&quot; string starting on line 17)
        (Missing semicolon on previous line?)
Possible unintended interpolation of @datastorer in string at /usr/local/apache/cgi-bin/Log2HTML.pl line 17.
Bareword found where operator expected at /usr/local/apache/cgi-bin/Log2HTML.pl line 23, near &quot;print &quot;Content&quot;
        (Do you need to predeclare print?)
Backslash found where operator expected at /usr/local/apache/cgi-bin/Log2HTML.pl line 23, near &quot;html\&quot;
Backslash found where operator expected at /usr/local/apache/cgi-bin/Log2HTML.pl line 23, near &quot;n\&quot;
String found where operator expected at /usr/local/apache/cgi-bin/Log2HTML.pl line 24, near &quot;print &quot;&quot;
  (Might be a runaway multi-line &quot;&quot; string starting on line 23)
        (Missing semicolon on previous line?)
Global symbol &quot;@datastorer&quot; requires explicit package name at /usr/local/apache/cgi-bin/Log2HTML.pl line 11.
syntax error at /usr/local/apache/cgi-bin/Log2HTML.pl line 23, near &quot;print &quot;&quot;
Global symbol &quot;@datastorer&quot; requires explicit package name at /usr/local/apache/cgi-bin/Log2HTML.pl line 17.
Execution of /usr/local/apache/cgi-bin/Log2HTML.pl aborted due to compilation errors.
Adam F
Solaris System Administrator
 
What was apache's problem with running it as a shell script?

--jim
 
A 'Premature end of script headers' message....

Adam F
Solaris System Administrator
 
#!/usr/bin/local/perl -w
# will this be better ?
# perl -c returned no errors
use strict;

my $webpage = &quot;/users/web/docs/adamlog.html&quot;;
my $uname = `uname -n`;
my $date = `date`;
my @datastorer;

&readfile;
&makehtml;
&endofscript;


sub readfile {
open (FILE, &quot;$webpage&quot;) || die &endofscript($!);
@datastorer = <FILE>;
close (FILE) || die endofscript($!);
}

sub makehtml {
print &quot;Content-type: text/html\n\n&quot;;
print &quot;<html><head><meta http-equiv=\&quot;Content-Type\&quot; content=\&quot;text/html; charset=iso-8859-1\&quot;>&quot;;
print &quot;<meta name=\&quot;GENERATOR\&quot; content=\&quot;Script generated by $0\&quot;>&quot;;
print &quot;<title>Extract from /var/log/progress.log</title>&quot;;
print &quot;</head><body bgcolor=\&quot;FFFFFF\&quot;><table border=\&quot;0\&quot; cellpadding=\&quot;3\&quot;><tr><td width=\&quot;25%\&quot;>&quot;;
print &quot;<IMG BORDER=0 SRC=\&quot;/images/ctlogo.jpg\&quot; WIDTH=99 HEIGHT=33 ALT=\&quot;ux-gbbri-mk1\&quot;>&quot;;
print &quot;</td><TD WIDTH=\&quot;75%\&quot;><CENTER><H1>Extract from /var/log/progress.log</H1></CENTER></TD>&quot;;
print &quot;</tr></TABLE><table border=\&quot;0\&quot; cellpadding=\&quot;3\&quot;><tr><td><b>Hostname:</b></td><td>$uname</td>&quot;;
print &quot;</tr></table><HR><FONT SIZE=\&quot;4\&quot;>The following data is an extract of the last 100 lines of the&quot;;
print &quot;/var/log/progress.log . This report<BR>is printed in reverse order with the youngest entry at the top&quot;;
print &quot;and oldest at the bottom.<font size=\&quot;2\&quot;><PRE>&quot;;
foreach (@datastorer) {
print &quot;$_<br>&quot;;
}
print &quot;</PRE><HR><P ALIGN=\&quot;CENTER\&quot;>&quot;;
print &quot;<A HREF=\&quot;./additional_reports.html\&quot;>BACK</A>&quot;;
print &quot;</P>Last Updated at $date</body></html>&quot;;
}

sub endofscript {
if ($_[0]) {print &quot;Content-type: text/html\n\n<html>DEAD : $_[0]&quot;;}
exit;
} ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
sub endofscript {
if ($_[0]) {print &quot;Content-type: text/html\n\n<html>DEAD : $_[0]&quot;;}
exit;
}

# should be

sub endofscript {
if ($_[0]) {print &quot;Content-type: text/html\n\n<html>DEAD : $_[0]</html>&quot;;}
exit;
} ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
you could have just added this to the shell script. where you have:

function HEADER {
echo &quot;<html>

do this:

function HEADER {
echo &quot;content-type: text/html

<html>
 
Sorry... here is an explanation. The client's browser is expecting 'header' information. The 'content-type: text/html' lets the browser know what type of information is being sent. There is other header info you can send also, but the above info is all you need to print to the browser.
 
I tried that earlier on.... But I got the same error. Adam F
Solaris System Administrator
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top