clear_logs (version 2.1)

You can also look at:
#! /usr/bin/perl

##############################################################################
#
# SYNTAX: clear_logs
#
# DESCRIPTION: This utility sets up the HTML job log as well as the
# DESCRIPTION: error and milestone indices.
# DESCRIPTION: First, any existing log files are renamed with ".old" appended to
# DESCRIPTION: their original names. Then the names of the log files are
# DESCRIPTION: obtained from the <TT>generate_filename</TT>
# DESCRIPTION: utility, and the HTML
# DESCRIPTION: headers are written.
#
# VERSION: 2.1
#
# HISTORY: 0.0 -> 1.0 8/19/96 
# HISTORY: Supplied missing </head> tags to all logs
# HISTORY: 
# HISTORY: 1.0 -> 2.0 1999-05-07
# HISTORY: Converted from ksh to perl
# HISTORY: 
# HISTORY: 2.0 -> 2.1 1999-06-28
# HISTORY: Moved code which adds "proc_error" parameter from the process script
# HISTORY: to here.
# HISTORY: Also added code to initialize the "nprocerrors" parameter.
#
# CALLS: $UTIL/read_parfile
# CALLS: $UTIL/generate_filename
#
##############################################################################

$UTIL = $ENV{"UTIL"};
$JOBPAR = $ENV{"JOBPAR"};


###################################################
# Initialize error counting parameters in job.par 
###################################################
`$UTIL/add_parameter $JOBPAR proc_error no b "Did a fatal proc error occur"`;
`$UTIL/add_parameter $JOBPAR nprocerrors 0 i "Number of errors in processing"`;

######################################################
# Clear out any old log files and initialize new ones
######################################################
chomp($seq = `$UTIL/read_parfile $JOBPAR sequence`);
chomp($ver = `$UTIL/read_parfile $JOBPAR seqprocnum`);

chomp($joblog = `$UTIL/generate_filename joblog`);
chomp($errlog = `$UTIL/generate_filename errlog`);
chomp($milestones = `$UTIL/generate_filename milestones`);
chomp($header = `$UTIL/generate_filename header`);

##########
# Job log
##########
if ( -e "$joblog" ) {
    rename "$joblog", "${joblog}.old";
    print "Moved $joblog to ${joblog}.old\n"
}

open(JOBLOG, ">>$joblog");
print JOBLOG "<HTML>\n";
print JOBLOG "<HEAD>\n";
print JOBLOG "<TITLE>";
print JOBLOG "Processing Job Log for Sequence $seq, version $ver";
print JOBLOG "</TITLE>\n";
print JOBLOG "</HEAD>\n";

print JOBLOG "<BODY>\n";
print JOBLOG "<H1>Processing Job Log for Sequence $seq, version ${ver}</H1>\n";

print JOBLOG "This is the complete and detailed record of how this\n";
print JOBLOG "sequence was processed.\n";
print JOBLOG "<P>\n";

print JOBLOG "The following information is also available:\n";
print JOBLOG "<UL>\n";
print JOBLOG "    <LI><STRONG><A HREF=\"${milestones}\">";
print JOBLOG "The processing log index</A></STRONG>\n";
print JOBLOG "    <LI><A HREF=\"${errlog}\">";
print JOBLOG "An index of processing errors</A>\n";
print JOBLOG "</UL>\n";
print JOBLOG "<HR>\n";

############
# Error log
############
if ( -e "$errlog" ) {
    rename $errlog, "${errlog}.old";
    print "Moved $errlog to ${errlog}.old\n";
}

open (ERRLOG, ">>$errlog");
print ERRLOG "<HTML>\n";
print ERRLOG "<HEAD>\n";
print ERRLOG "<TITLE>\n";
print ERRLOG "Errors in Processing for Sequence $seq, version $ver";
print ERRLOG "</TITLE>\n";
print ERRLOG "</HEAD>\n";

print ERRLOG "<BODY>\n";
print ERRLOG "<H1>Errors in Processing for Sequence $seq, version ${ver}</H1>\n";

print ERRLOG "This page gives a list of all the errors encountered in\n";
print ERRLOG "processing this sequence. These errors have been checked by\n";
print ERRLOG "the processing staff and should not affect the validity of\n";
print ERRLOG "these data. If you have any questions please contact\n";
print ERRLOG "<TT>ascahelp\@legacy.gsfc.nasa.gov</TT>.\n";
print ERRLOG "<P>\n";

print ERRLOG "The following information is also available:\n";
print ERRLOG "<UL>\n";
print ERRLOG "    <LI><STRONG><A HREF=\"${milestones}\">";
print ERRLOG "The processing log index</A></STRONG>\n";
print ERRLOG "    <LI><A HREF=\"${joblog}\">The entire processing log</A>\n";
print ERRLOG "</UL>\n";
print ERRLOG "<HR>\n";
print ERRLOG "<OL>\n";

################
# Job log index
################
if ( -e "$milestones" ) {
    rename $milestones, "${milestones}.old";
    print "Moved $milestones to ${milestones}.old\n";
}

open (MILESTONES, ">>$milestones");
print MILESTONES "<HTML>\n";
print MILESTONES "<HEAD>\n";
print MILESTONES "<TITLE>";
print MILESTONES "Processing Log Index for Sequence $seq, version $ver";
print MILESTONES "</TITLE>\n";
print MILESTONES "</HEAD>\n";

print MILESTONES "<BODY>\n";
print MILESTONES "<H1>Processing Log Index for Sequence $seq, ";
print MILESTONES "version ${ver}</H1>\n";

print MILESTONES "The processing log documents the creation of the files\n";
print MILESTONES "in this distribution\n";
print MILESTONES "and indicates any errors that may have occurred.\n";
print MILESTONES "This page gives an index to the major processing steps\n";
print MILESTONES "and the 24 hour clock time at which the event occurred.\n";
print MILESTONES "<P>\n";
print MILESTONES "The following information is also available:\n";
print MILESTONES "<UL>\n";
print MILESTONES "    <LI><STRONG><A HREF=\"${header}\">";
print MILESTONES "The processing header page</A></STRONG>\n";

print MILESTONES "    <LI><A HREF=\"${errlog}\">";
print MILESTONES "An index of processing errors</A>\n";
print MILESTONES "    <LI><A HREF=\"${joblog}\">";
print MILESTONES "The entire processing log</A>\n";
print MILESTONES "</UL>\n";
print MILESTONES "<HR>\n";
print MILESTONES "<OL>\n";

exit 0;