We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

how to include SSI in CGI(perl) script?

Medium Priority
688 Views
Last Modified: 2013-11-18
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
Comment
Watch Question

Commented:
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.
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
#You could also
print <<EOF;
.
Last Updated and Validated on @{[scalar localtime ((stat"addentry.pl")[9])]}
.
EOF

Author

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

I increased the points, hoping you are more interested.


Author

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

I increased to points, hoping you are more interested.


Commented:
Well, that's a good first step, next you need to tell us what server you are using :-)

Commented:
print `your_ssi.cgi`;

that would do it.

GL
t

Author

Commented:
for simplicity, let's say APACHE server.

Commented:
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

Author

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.
 

Commented:
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

Author

Commented:
Can you give me an example?

Thanks

Commented:
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

Author

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.

Author

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

Thanks for help
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Commented:
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.

Author

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?:)


Commented:
Not easily, you have to ask customer service.

In this case that's not necessary, but thanks.
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
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

Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.