RE: first cgi

by "Brian A. Sayrs" <sayrs(at)southwindsolutions.com>

 Date:  Mon, 21 Feb 2000 13:36:14 -0800
 To:  "'Roger Harness'" <magic32(at)jps.net>,
"hwg-techniques(at)mail.hwg.org" <hwg-techniques(at)mail.hwg.org>
  todo: View Thread, Original
Hi, Roger,

	Perl is not a shell, so commands like "echo" don't exist.  A quick way =
of creating a page with only the date on it is this:

SCRIPT 1:
#!/usr/bin/perl
print "Content-type: text/plain\n\n";	# the magical content-type line
print time;				# of course, this is UNIX epoch (in seconds)

This first script can be seen in action at =
http://www.sowinso.com/cgi-bin/date1.cgi

It's advantage is that it's fast, and if it's a computer reading/storing =
the info, it's the best way to go.  Probably not best for CGI output =
since it's probably not formatted the way you want, so you will want to =
use the gmtime or localtime functions to make it human-readable.

SCRIPT 2:
#!/usr/bin/perl
print "Content-type: text/plain\n\n";	# \n is a newline
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =3D gmtime(time);
@month =3D ("January", "February", "March", "April", "May", "June", =
"July", "August", "September", "October", "November", "December");	=
#names of the month
@weekday =3D ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", =
"Friday", "Satruday");	#names of the days
$year +=3D 1900;				# add 1900 to the year
print "Today is $weekday[$wday], $month[$mon] $mday, $year (GMT)";

This second script can bee seen in action at =
http://www.sowinso.com/cgi-bin/date2.cgi

This script is the slowest of the three presented here, but it is the =
most configurable.  You can decide which elements to use and in what =
order without too many hassles.  Now, in the specific case you gave =
earlier (when you're attempting to run a program outside Perl) you can =
do this:

SCRIPT 3:
#!/usr/bin/perl
print "Content-type: text/plain\n\n";	# if it's CGI, you have to have at =
least one header line!
print `date`;				# print directs the output of the system to the browser

This third script can be see in action at, you guessed it, =
http://www.sowinso.com/cgi-bin/date3.cgi

It is fast, and readable, if not entirely so.  I hope I didn't give you =
too much information.  What I suggest you do is to look to see if Perl =
supports a command before you use it by doing this:

perldoc -f functioname

The perldoc is rather helpful, and it's on any computer which has Perl.  =
What?  You don't have Perl?  Download it at http://www.perl.com or at =
http://www.activestate.com/ActivePerl/ for win32.  I'm sure you'll find =
it useful for debugging (the command to check to see if your script will =
compile is "perl -c scriptname"), and it's FREE.  Can't beat that.  :)

HTH,
Brian A. Sayrs
Owner, Southwind Solutions


-----Original Message-----
From:	Roger Harness [SMTP:magic32(at)jps.net]
Sent:	Monday, February 21, 2000 11:19 AM
To:	hwg-techniques(at)mail.hwg.org
Subject:	first cgi

Ok technique gurus, I have a question for you. I'm trying to do just a
basic cgi (script?). I'm using my "HTML 4 In a Week" book, along with =
the
tips from my hosting service. (hostsave.com, thank you Shelley!)

Using arachnophilia, I typed this:

#!/usr/bin/perl

echo Content-type: text/plain
echo

usr/bin/date

I saved this as getdate.cgi then uploaded it into my cgi-bin using =
WS_FTP
95 le as ASCII. That's correct, right??

I then made a basic html page called getthedate.html with this code:

<html>
<!-- Copyright (c) 2webslingers -->
<head>
<title>practice cgi</title>
</head>

<A href=3D"http://www.2webslingers.com/cgi-bin/getdate.cgi">display the
date</A>
</body>
</html>


so when I click on "display the date" I *should* get today's date, =
correct?
(BTW, hostsave does NOT allow telnet, so I can't just go to the command
prompt and try typing date :)

Instead of today's date showing up, I get:

**********************************
Internal Server Error
The server encountered an internal error or misconfiguration and was =
unable
to complete your request.
Please contact the server administrator, webmaster(at)2webslingers.com and
inform them of the time the error occurred, and anything you might have
done that may have caused the error.

More information about this error may be available in the server error =
log.
**********************************

the server log doesn't give me any helpful info, and hostsave doesn't =
give
any tech support for cgi scripting.

Does anyone have any advice/suggestions here? I've used the cut and =
paste
FormMails before, and I can usually get stuff like that to work, but I'm
just not having any luck with this simple, stupid date thing. I've tried
just about everything (changing parts of code, where I put the files =
etc,
but no luck. Any help would be greatly appreciated!!!


Sincerely,

Roger Harness

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA

This page is part of a preserved archive of archives.hwg.org. The site is no longer active and its content is not maintained. For enquiries about this archive, write to archive(at)iwanet.org.