Hello,
If anyone recalls Jack brought up the question of determining of an
action was successful or not. It sparked me to mention a more
sophisticated use of the error messages. I was just editing a script
that I wrote long ago and I thought it was interesting.
I use a common file for common things I do in cgi scripts. I call it
common.cgi or sometimes I make it special for a big project. But I
nearly always have a common.cgi in every cgi-bin. One of my common
actions is to print all the environment varialbes. I just stick this
in a script:
&print_env;
and it causes the script to print all env variables and exit.
So I stuck it in a script to see the env variables but it didn't
work. I realized that I didn't even have a call to common.cgi nor
did one exist in the cgi-bin and yet no error was generated. Ah, but
one was. It was emailed to me. And it only worked because of the
eval.
Look at this for a clue:
if($@) {
&print_error("$@");
&send;
}
It catches the error, sends me the error via email and then
continues.
Here is the script:
#! /usr/local/bin/perl5.00401
$send_mail_to = "webmaster\@your name.com";
$reply_to = "webmaster\@your name.com";
$Mail_From = "From Me <service\@your name.com>";
$subject = "Subject Line Here";
$thank_you_subject = "We appreciate your interest";
$cc = "webmaster\@germantown.net";
$mailprog = '/bin/sendmail';
$linkfile =
"/usr/local/etc/httpd/htdocs/memphisart/images/banners/banner_track.tx
t";
$go = $ENV{QUERY_STRING};
$go = "http://www.germantown.net/index.html" if !$go;
eval{&main;};
if($@) {
&print_error("$@");
&send;
}
sub main {
&get_date;
&print_env;
open(L,">>$linkfile") || open(L,">$linkfile") || &print_error("Cannot
open $linkfile"); flock(L,2) || &print_error("Cannot flock
$linkfile"); print L
"$go\|$ENV{'HTTP_REFERER'}\|$ENV{'REMOTE_HOST'}\|$ENV{'HTTP_USER_AGEN
T'}\|$date\n"; flock(L,8) || &print_error("Cannot unflock
$linkfile"); close(L); &send;
}
sub send {
print "Status: 302\n";
print "Location: $go\n\r\n\r";
exit;
}
###########################################
sub print_error {
my $err = shift;
open(MAIL,"|$mailprog -t") || warn "Mail problem in $0";
print MAIL "To: $send_mail_to\n";
print MAIL "cc: webmaster\@germantown.net\n";
print MAIL "Reply-to: $send_mail_to\n";
print MAIL "Errors-to: $send_mail_to\n";
print MAIL "From: $Mail_From\n";
print MAIL "Subject: $subject\n\n";
print MAIL <<END;
Error: $err
Hi, won't you be my friend.
END
close (MAIL);
}
#############################################}
sub get_date {
@days =
('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Satur
day'); @months =
('January','February','March','April','May','June','July',
'August','September','October','November','Decemb
er');
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime(time); if ($hour < 10) { $hour = "0$hour"; } if ($min <
10) { $min = "0$min"; } if ($sec < 10) { $sec = "0$sec"; }
$month=$mon + 1;
$date = "$month\/$mday\/$year";
return $date;
}
_________________________________________________________
Peter J. Schoenster [EMAIL PROTECTED]
Exercise Your Brain..Read a Book http://www.rede.com/
Free CGI Scripts and Applications
http://www.rede.com/samples/index.html
____________________________________________________________________
--------------------------------------------------------------------
Join The Web Consultants Association : Register on our web site Now
Web Consultants Web Site : http://just4u.com/webconsultants
If you lose the instructions All subscription/unsubscribing can be done
directly from our website for all our lists.
---------------------------------------------------------------------