Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 606
  • Last Modified:

how to include SSI in CGI(perl) script?

Greetings,

Does anybody know how to include a SSI into a perl script? here is an example:
#! /usr/bin/perl -w

select(STDOUT); $|=1;

print <<EOF;
Content-TYPE: text/html

<html>
....

<address>
Last Updated and Validated  on <!--#flastmod file="addentry.pl" -->
</address>
</body></html>
EOF

I know I could use stat or lstat function to get the result. just curious about how to do
it in SSI.

Thanks in advance

Peggy
0
pyang051597
Asked:
pyang051597
  • 8
  • 4
  • 4
  • +2
1 Solution
 
alamoCommented:
Normally the server doesn't check the CGI output for SSI directives, as it would waste server time. You have to configure the server to tell it to parse .cgi (or .pl) output for SSI.
0
 
ozoCommented:
#You could also
print <<EOF;
.
Last Updated and Validated on @{[scalar localtime ((stat"addentry.pl")[9])]}
.
EOF
0
 
pyang051597Author Commented:
How to configure the server to parse cgi output for SSI?

I increased the points, hoping you are more interested.


0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
pyang051597Author Commented:
How to configure the server to parse cgi output for SSI?

I increased to points, hoping you are more interested.


0
 
alamoCommented:
Well, that's a good first step, next you need to tell us what server you are using :-)
0
 
tpryorCommented:
print `your_ssi.cgi`;

that would do it.

GL
t
0
 
pyang051597Author Commented:
for simplicity, let's say APACHE server.
0
 
tpryorCommented:
oh i see, you are just curious.  you dont actually want to execute another (SSI) cgi script.

you wouldnt really configure the server to parse cgi output.

because it would be more efficent to call the (SSI) script within your perl script.

you just want to know how to configure your server that way so you can make sure that it is not configured that way to increase performance.  

oh, now I get it <gr>

t

0
 
pyang051597Author Commented:
Yes, I like to know how to call the ssi script within perl script, but I dont know HOW, and I dont understand your "print `your_ssi.cgi`".  I think configuration of the server may be
easier.  

I am still interested in the answer, in both way, if possible

Thanks again.
 
0
 
tpryorCommented:
print `your.cgi` executes another script and puts it's output where it was called from in the first script. dont need to configure the server to get the same results, more efficient, and IMHO its eassier <gr>

t
0
 
pyang051597Author Commented:
Can you give me an example?

Thanks
0
 
tpryorCommented:
yep, Ill make it simple but you could have it be as complicated as you like in the real world no restrictions on this because they are just perl scripts.

make two perl scripts
In one (the ssi) set it uo the normal way except you dont need to print out the server header line (content-type: text/html\n\n).

just do
print "this is out put from the ssi<br>\n";

In the other
set it up in the normal way and dont forget the header line.
print "this is out put from my cgi<br>\n"
print `ssi.cgi`; # make sure the files are in the same dir or
                                # include the full path path/ssi.cgi
print "here is some more out put from my cgi<br>\n";

that should give you an idea of how it works.  It is quite simple.

GL,
t
0
 
pyang051597Author Commented:
OK, i made 2 files, one is ssi.pl as follows:
#! /usr/bin/perl -w

print "this is out put from the ssi<br>\n";
print <<EOF;
Last Updated and Validated  on <!--#flastmod file="ssi.pl" -->
EOF

another file is called ssi_1.pl

#! /usr/bin/perl -w

select(STDOUT); $|=1;

print <<EOF;
Content-TYPE: text/html

<html>
<body>
EOF

print "this is out put from my cgi<br>\n" ;
print `./ssi.pl`;
print "</body>";
print "</html>";

but it did not work, what's wrong? I am on SUN workstation, using
APACHE server, the server has been configured so it SSI is included.

0
 
pyang051597Author Commented:
Sorry, tpryor, I have to reopen the question, since the way you told me didn't work.

Thanks for help
0
 
mikegrbCommented:
To answer you original question:

It is impossible (AFAIK).  If it where you would:
Add "AddHandler server-parsed .pl" to conf/srm.conf and then
'killall -HUP httpd' however the CGIs ending in .pl are now
treated as if they where .shtml and thus they are not executed
but simply parsed for SSI directives and sent to the browser.

You might take a look at
http://www.cgi-resources.com/Programs_and_Scripts/Perl/Server_Side_Include_Parsing/
and similiar sites and adapt an existing CGI to use as a require.


0
 
alamoCommented:
Hi pyang,

As mikegrb says, Apache can not be configured to do SSI processing on the output of a script. (Their FAQ says they plan to add it). The link he gave has some good alternatives.

To explain why tpryor's approach didn't work - it was not a way to do <!--#flastmod file="ssi.pl" -->, it was a way to do <!--#exec cgi="ssi.pl" -->. So yes it was a way to simulate one feature of SSI (included scripts), but not the feature you originally asked for (flastmod).

The real answer was far simpler anyway, and now you have it.
0
 
pyang051597Author Commented:
Thank you very much.

Alamo, I wish I could give you some credits as well. but I guess
there is no way to split the points, right?:)


0
 
alamoCommented:
Not easily, you have to ask customer service.

In this case that's not necessary, but thanks.
0
 
ozoCommented:
print <<EOF;
<address>
Last Updated and Validated  on <!--#flastmod file="addentry.pl" -->
<address>
EOF
#can be emulated with
print <<EOF;
<address>
Last Updated and Validated on @{[scalar localtime ((stat"addentry.pl")[9])]
<address>
EOF

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 8
  • 4
  • 4
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now