Implementing custom CGI scripts
Our UNIX web servers have the capability to run CGI scripts in your very own
"cgi-local" directory. Scripts may be written in Perl, Unix SH, KSH, CSH, and C
(NOT C++) languages. Perl is our language of choice as it is a world standard and is well
suited to CGI. In addition, Perl code does not require manual compilations whereas C code
must be compiled* on our web servers prior to use.
NT hosting customers have a "cgi-bin" directory. Customers may write scripts
in PERL, C, C++.
Here are some helpful tips to follow when installing scripts;
UNIX Shell Scripts
- Upload to your cgi-local directory to ensure proper file permission settings
- Upload in ASCII transfer mode (and NOT BINARY mode)
- The first line of each script must read: #!/bin/sh , #!/bin/csh or #!/bin/ksh based on
whichever shell scripts you prefer using.
- Reference the script using /cgi-local (and NOT /cgi-bin)
- Always remember to include echo "Content-type: text/html\n\n"
Perl Scripts
- Upload to your cgi-local directory to ensure proper file permission settings
- Upload in ASCII transfer mode (and NOT BINARY mode)
- The first line of each script must read: #!/usr/local/bin/perl
- Use the Perl script checker in your Control Panel to check syntax.
- Reference the script using /cgi-local (and NOT /cgi-bin)
- Always remember to include print "Content-type: text/html\n\n"; or
alternatively using the Perl module CGI.pm (If you do not, your scripts will not run and
you will get an Internal Server Error message).
use CGI qw(:cgi-lib :standard);
print header();
If a script calls another file within your account, but the script does NOT require a
URL, you need to use the system path. Instead of using the absolute path to your home
directory ("/www26/web/someid"), you should instead use the DOCUMENT_ROOT
environment variable ($ENV{DOCUMENT_ROOT} in Perl) to determine the path of your files or
programs within a script.
e.g.
From:
/www23/web/yourid/data/fact.html
To:
$ENV{DOCUMENT_ROOT}/data/fact.html
The UNIX system path to the sendmail program on your server is
/usr/lib/sendmail
The UNIX system path to the date command is
/sbin/date
Automated Tasks (cron.sh)
One automated task daily. Task scheduled only between 2:00am to 5:00am Eastern. Place
the script that you want to run in the cron.sh file in your cgi-local directory. There can
only be one cron.sh run daily.
#/bin/sh
/u/web/userID/cgi.local/cronjob.pl >> /u/web/userID/cgi.local/cron.log 2>&1
This script will run the cronjob.pl script and output any information that this script
generates into cron.log. You can have multiple script entries in your cron.sh file.
*** We can run only two C compilations for you. As such, we suggest Perl as an
alternative scripting language. A work around may be available to seasoned C developers.
C++ is NOT supported.
|