#!/usr/local/bin/perl # #------------------------------------------------------------------------- # # dolog.cron - A perl script used to convert Framemaker (.html) files # to HTML (.html) files. The script attempts to clean up # any stray files, such as .mif & .htags files that are # created during the conversion process. # # The script also groups the .html files by month # in the HTML archive directory by putting them in monthly # archive subdirectories. # # Version History: # # Ver. Initals Date Description # --- ------- -------- ------------------------------------- # HC1.1 saw 11/17/1997 Add capability to followup existing entries # Also won't trash entries with INDEX, PREV, or NEXT. # HC1.2 saw 11/19/1997 Rewrite squirly HTML (no more MULTICOL) so # that netscape Find works on logdir pages. # HC1.3 saw 11/20/1997 If an item is followed up by the very next # entry and if it's the only followup, # don't show it in index. # HC1.35 saw 11/20/1997 Index formatting tweaks. # (Remove seconds, more room for name) # HC1.4 saw 12/3/1997 Separate indexes for All, Only automatic, All # but automatic. # HA1.1 jv 07/12/1998 Ported HC1.4 to HA1.1 # HA1.2 rwm 01/6/2000 Incorporate S.Wood's Y2K fixes # #------------------------------------------------------------------------- $SCRIPT_VERSION="HA1.2"; #=================================================================================== # include some of the standard PERL subroutines #=================================================================================== require "stat.pl"; require "timelocal.pl"; $CLOG = "clog"; $FLOG = "flog"; $SLOG = "slog"; $ELOG = "elog"; $HALOG = "halog"; $HBLOG = "hblog"; $HCLOG = "hclog"; $webmgr = "/home/adaq/public_html/halog"; $httptj = "A HREF=http://www.cebaf.gov/~adaq/halog"; #$auto_regexp = "^Run \\d+:"; # Regular expression to find automatic entries $auto_regexp = "End_of_Run"; # Regular expression to find end of run entries $auto_regexp2 = "Accounting"; # Regular expression to find accounting entries $auto_regexp3 = "Start_Run"; # Regular expression to find accounting entries #=================================================================================== #=================================================================================== #$httpwm = "~volmer/elogtemp/html/internal"; #$logbook = $ARGV[0]; #if ($logbook eq $CLOG) { # #print( "using:: clog \n" ); # close(STDERR); # open( STDERR, "/usr/csite5/web/html/internal/cryo/clog/dolog.log"); # $tmpdir = "$webmgr/html/internal/cryo/clog/tmp_html/"; # $htmldir = "$webmgr/html/internal/cryo/clog/html/"; # $logfile = "$webmgr/html/internal/cryo/clog/dolog.perl.log"; # $refdir = "cryo/clog"; # $scrollname = "clog_selection"; # $LOGTITLE = "CHL"; #} #elsif ($logbook eq $FLOG) { # #print( "using:: flog \n" ); # close(STDERR); # open( STDERR, "/usr/csite5/web/html/internal/fel/flog/dolog.log"); # $tmpdir = "$webmgr/html/internal/fel/flog/tmp_html/"; # $htmldir = "$webmgr/html/internal/fel/flog/html/"; # $logfile = "$webmgr/html/internal/fel/flog/dolog.perl.log"; # $refdir = "fel/flog"; # $scrollname = "flog_selection"; # $LOGTITLE = "FEL"; #} #elsif ($logbook eq $SLOG) { # #print( "using:: slog \n" ); # close(STDERR); # open( STDERR, "/usr/csite5/web/html/internal/software/softlog/dolog.log"); # $tmpdir = "$webmgr/html/internal/software/softlog/tmp_html/"; # $htmldir = "$webmgr/html/internal/software/softlog/html/"; # $logfile = "$webmgr/html/internal/software/softlog/dolog.perl.log"; # $refdir = "software/softlog"; # $scrollname = "slog_selection"; # $LOGTITLE = "SOFTWARE"; #} #elsif ($logbook eq $HALOG) { # #print( "using:: halog \n" ); $logbook = "HALOG"; close(STDERR); open( STDERR, "/u/home/adaq/halog/log/dolog.log"); $tmpdir = "$webmgr/log/tmp_html/"; $htmldir = "$webmgr/log/html/"; $logfile = "$webmgr/log/dolog.perl.log"; $refdir = "log"; $scrollname = "halog_selection"; $LOGTITLE = "HALL A"; #} #elsif ($logbook eq $HBLOG) { # #print( "using:: hblog \n" ); # close(STDERR); # open( STDERR, "/usr/csite5/web/html/internal/hallb/hblog/dolog.log"); # $tmpdir = "$webmgr/html/internal/hallb/hblog/tmp_html/"; # $htmldir = "$webmgr/html/internal/hallb/hblog/html/"; # $logfile = "$webmgr/html/internal/hallb/hblog/dolog.perl.log"; # $refdir = "hallb/hblog"; # $scrollname = "hblog_selection"; # $LOGTITLE = "HALL B"; #} #elsif ($logbook eq $HCLOG) { # #print( "using:: hclog \n" ); #$logbook = "HCLOG"; # close(STDERR); # open( STDERR, "/u/home/cdaq/hclog/log/dolog.log"); # $tmpdir = "$webmgr/log/tmp_html/"; # $htmldir = "$webmgr/log/html/"; # $logfile = "$webmgr/log/dolog.perl.log"; # $refdir = "log"; # $scrollname = "hclog_selection"; # $LOGTITLE = "HALL C"; # #} #elsif ($logbook eq $ELOG) { # #print( "using:: elog \n" ); # close(STDERR); # open( STDERR, "/usr/csite5/web/html/internal/ops/daily_activity_log/dolog.log"); # $tmpdir = "$webmgr/html/internal/ops/daily_activity_log/tmp_html/"; # $htmldir = "$webmgr/html/internal/ops/daily_activity_log/html/"; # $logfile = "$webmgr/html/internal/ops/daily_activity_log/dolog.perl.log"; # $refdir = "ops/daily_activity_log"; # $scrollname = "elog_selection"; # $LOGTITLE = "OPERATIONS"; #} #else { # #print( "using:: elog \n" ); # close(STDERR); # open( STDERR, "/usr/csite5/web/html/internal/ops/daily_activity_log/dolog.log"); # $tmpdir = "$webmgr/html/internal/ops/daily_activity_log/tmp_html/"; # $htmldir = "$webmgr/html/internal/ops/daily_activity_log/html/"; # $logfile = "$webmgr/html/internal/ops/daily_activity_log/dolog.perl.log"; # $refdir = "ops/daily_activity_log"; # $scrollname = "elog_selection"; # $LOGTITLE = "OPERATIONS"; #} #=================================================================================== # set up the file suffixs that we will use #=================================================================================== $htmlSuffix = ".html"; $archiveSuffix = "_archive"; #=================================================================================== # assign the needed environment variables for child processes #=================================================================================== #$ENV{ 'FMHOME' } = "/usr/csite/frame"; #$ENV{ 'PATH' } = "/usr/bin:/usr/local/bin:/usr/bin/X11"; #=================================================================================== # define the days of the week for lookup later on #=================================================================================== @dayofweek[0] = "Sunday"; @dayofweek[1] = "Monday"; @dayofweek[2] = "Tuesday"; @dayofweek[3] = "Wednesday"; @dayofweek[4] = "Thursday"; @dayofweek[5] = "Friday"; @dayofweek[6] = "Saturday"; #=================================================================================== # define the months for lookup later on #=================================================================================== @month["01"] = "January"; @month["02"] = "February"; @month["03"] = "March"; @month["04"] = "April"; @month["05"] = "May"; @month["06"] = "June"; @month["07"] = "July"; @month["08"] = "August"; @month["09"] = "September"; @month["10"] = "October"; @month["11"] = "November"; @month["12"] = "December"; #=================================================================================== #printout the greeting message #=================================================================================== #open(LOGDIR, $logdir) || die "dolog can't open LOGDIR: $!\n"; #print( "dolog v1.0 - by Valerie Bookwalter / Controls Group\n" ); #system( "echo running dolog: `date` >> $logfile" ); select( ( select(STDOUT), $| = 1)[0]); #=================================================================================== # Get a snapshot of the directories so that we can look through the file entries #=================================================================================== opendir(TMPDIR, $tmpdir) || die "dolog can't open TMPDIR: $!\n"; #print( "dolog v1.0 - by Valerie Bookwalter / Controls Group\n" ); #=================================================================================== # read the filenames and sort the names in the tmp_html_dir directory #=================================================================================== @tmp_array=sort( readdir( TMPDIR ) ); #=================================================================================== # search directory and only look at files in the form YYMMDDhhmmss.html # where YY=Year, MM=Month, DD=Day, hh = hour, mm = minute, ss = seconds #=================================================================================== @tmp_array=grep( /\d{12}\.html$/, @tmp_array ); #=================================================================================== # place us in the $tmpdir directory for simplicity #=================================================================================== chdir $tmpdir || die "dolog - can't chdir to $tmpdir: $!\n"; #=================================================================================== # for each valid html filename execute this loop #=================================================================================== $tindex=0; $lastfile = @tmp_array[$tindex]; foreach $tmp_filename (@tmp_array) { $tindex++; #=================================================================================== # figure out what the root part of the filename is (take off the .html) #=================================================================================== $offset = index( $tmp_filename, $htmlSuffix, 0 ); $root_filename = substr( $tmp_filename, 0, $offset); #=================================================================================== # use the first 4 characters of the filename as the archive directory root #=================================================================================== $archiveDir = substr( $root_filename, 0, 4 ) . $archiveSuffix . "/"; $html_filename = $root_filename.$htmlSuffix; #=================================================================================== # update the html file #=================================================================================== &update_html( $root_filename ); } #=================================================================================== # # Now that we have created all of the up to date HTML files we need to # update all of the logbook entries. We'll just update all of them rather # than checking to see if they need updating to make development faster. # A check to see if it needs updating can be added to a future version. # #=================================================================================== opendir(HTMLARCHIVE, $htmldir ) || die "dolog can't open HTMLDIR: $!\n"; #=================================================================================== # Read in the archive directories and create a logbook entry listing for each # validly named HTML file in that directory. #=================================================================================== @html_array=sort reverse readdir( HTMLARCHIVE ); #Begin Y2K Fix @html_dirs_the1990s=reverse sort grep( /9..._archive$/, @html_array ); @html_dirs_newmillenium=reverse sort grep( /[0-8]..._archive$/, @html_array ); @html_dirs = (@html_dirs_newmillenium,@html_dirs_the1990s); #End Y2K Fix $html_archive = @html_dirs[0]; chdir $htmldir . $html_archive || die "dolog - can't chdir to $htmldir: $!\n"; &month_update( $archiveDir ); #foreach $html_archive (@html_dirs) #{ # chdir $htmldir . $html_archive || die "dolog - can't chdir to $htmldir: $!\n"; # &month_update( $archiveDir ); #} closedir( HTMLARCHIVE ); #=================================================================================== # Now that we have created a month html listing we need to create a last # week listing. This may cross monthly archives. #=================================================================================== chdir $htmldir || die "dolog - can't chdir to $htmldir: $!\n"; #=================================================================================== # The week listing is the listing of the last 7 days of logbook entries. This # is the most common place that people go to look at logbook entries. At the # end of the week listing is a listing of the archives that contain # the monthly entries. # # create a temporary logdir.html file named logdir.new.html. At the end we'll # replace the logdir.html with the logdir.new.html file. This way if anything # crashes we don't wipe out a valid and useful but out of date logdir.html. # Thus we ensure that people can still read some of the log entries, just not # the latest one. #=================================================================================== $firstime = 0; open( OUTFILE, ">logdir.new.html" ); open( OUTFILE_AUTO, ">logdir_auto.new.html" ); open( OUTFILE_AUTO2, ">logdir_auto2.new.html" ); open( OUTFILE_NOAUTO, ">logdir_noauto.new.html" ); open( OUTFILE_NOAUTO2, ">logdir_noauto2.new.html" ); &print_logdirhead(OUTFILE,"Full Listing"); &print_logdirhead(OUTFILE_AUTO,"Run Ends Only"); &print_logdirhead(OUTFILE_AUTO2,"Run Starts Only"); &print_logdirhead(OUTFILE_NOAUTO,"Accounting Only"); &print_logdirhead(OUTFILE_NOAUTO2,"All EXCEPT Automatic Entries"); #=================================================================================== #=================================================================================== #=================================================================================== #=================================================================================== $oneDay = 24 * 60 * 60; # 24 hours * 60 minutes/hour * 60 seconds/minute $oldday = "none"; # we haven't had a day yet for( $day = 0; $day < 7; $day++ ) { #=================================================================================== # figure out the month and day that we are looking at this time through # the loop # VDB:: are we geting the right date/time at 1am?? #=================================================================================== ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime( time() - ( $oneDay * $day ) ); #localtime( time() - ( $oneDay * $day ) - 60*60*2 ); # Local time returns (year-1900). Just keep the last tow digits since we only # use two digits of year in filenames. Fix this log book before 2090. $year %= 100; #=================================================================================== # create the root of the files we'll be looking at #=================================================================================== $html_wildcard = sprintf( "%2.2d%2.2d%2.2d.......html", $year, $mon+1, $mday ); #=================================================================================== # create the archive directory name we'll be looking in #=================================================================================== $html_archive = substr( $html_wildcard, 0, 4 ) . "_archive"; #=================================================================================== # open the directory #=================================================================================== # opendir(HTMLDIR, $htmldir.$html_archive) || die "dolog can't open HTMLDIR/archive: $!\n"; if (opendir(HTMLDIR, $htmldir.$html_archive)) { @html_array=reverse sort readdir( HTMLDIR ); #=================================================================================== # only use the files with our wildcard #=================================================================================== @html_array=grep( /$html_wildcard/, @html_array ); closedir( HTMLDIR ); #=================================================================================== # create the date and shift to output to the logdir.html file #=================================================================================== foreach $html_filename (@html_array) { $KEYWORD="no_key"; $NAMWORD="no_name"; $ENUMBER="0"; $followuplist = ""; open(TMPFILE, "$htmldir$html_archive/$html_filename" ) || die "dolog can't open TMPFILE: $!\n"; while(chomp($line = )){ if ($line =~ /keyword=/) { $tempkey="$'" if $line =~ /keyword=/; $KEYWORD = "$`" if $tempkey =~ /
/; $KEYWORD = "$`" if $tempkey =~ /

/; $KEYWORD = "$`" if $tempkey =~ /

/; last; # } elsif ($line =~ /^

Followups: (.*)<\/h4>/) { } elsif ($line =~ /^

Followups:<\/h4>(.*)$/) { $followuplist = $1; } if ($line =~ /User name/) { $tempkey="$'" if $line =~ /User name/; $NAMWORD = "$`" if $tempkey =~ /<\/h4>/; } if ($line =~ /Entry number/) { @enumber = split(' ',$line); @enumber = split('<',$enumber[2]); $ENUMBER = $enumber[0]; } } close(TMPFILE); $html_date=substr( $html_filename, 2, 2 ) . "/" . substr( $html_filename, 4, 2 ) . "/" . substr( $html_filename, 0, 2 ); $html_shift=substr( $html_filename, 6, 2 ) . ":" . substr( $html_filename, 8, 2 );# . ":" . # substr( $html_filename, 10, 2 ); #=================================================================================== # figure out the seconds since 1970 of the current shift #=================================================================================== @datetime[0] = 0; @datetime[1] = 0; @datetime[2] = substr( $html_filename, 6, 2 ); @datetime[3] = substr( $html_filename, 4, 2 ); @datetime[4] = substr( $html_filename, 2, 2 ) -1; @datetime[5] = substr( $html_filename, 0, 2 ); $dtime = &timelocal( @datetime); #=================================================================================== # Figure out what day this shift was on. #=================================================================================== $thisday = (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday)[(localtime($dtime))[6]]; #Saturday)[(localtime($dtime+60*60-1))[6]]; #=================================================================================== # if the day has change since the last entry, then print out the # new day to make it easier for people to find logbook entries by # day (i.e. Monday, Tuesday, ..., Sunday #=================================================================================== if ( $oldday ne $thisday ) { if ($firstime == 0) { $firstime = 1; } else { printf( OUTFILE "\n" ); printf( OUTFILE_AUTO "\n" ); printf( OUTFILE_AUTO2 "\n" ); printf( OUTFILE_NOAUTO "\n" ); printf( OUTFILE_NOAUTO2 "\n" ); } $dayheader = "

$thisday

\n
\n";
		print OUTFILE $dayheader;
		print OUTFILE_AUTO $dayheader;
		print OUTFILE_AUTO2 $dayheader;
		print OUTFILE_NOAUTO $dayheader;
		print OUTFILE_NOAUTO2 $dayheader;
		$oldday = $thisday;
	}

#===================================================================================
#       print out the logbook entry line
#===================================================================================
	$entry_line = sprintf("
  • %6s %s %s %-15.13s %s\n", $html_archive . "/" . $html_filename, $ENUMBER, $html_date, $html_shift, $NAMWORD, $KEYWORD ); print OUTFILE $entry_line; if($KEYWORD=~/$auto_regexp/o) { print OUTFILE_AUTO $entry_line; } elsif($KEYWORD=~/$auto_regexp2/o) { print OUTFILE_NOAUTO $entry_line; } elsif($KEYWORD=~/$auto_regexp3/o) { print OUTFILE_AUTO2 $entry_line; } else { print OUTFILE_NOAUTO2 $entry_line; } # If the followuplist consists of a single followup, and that followup has an # entry number just one more than $ENUMBER, then don't put it in the index. # Tell how many followups there are by counting "
  • ". if($followuplist) { # $followuplist =~ s/a>,
  • $followuplist\n"); # Don't print out followups when there is just one and it is the very next entry. if(index($followuplist,"
  • ") == rindex($followuplist,"
  • ")) { $followuplist=~/> *(\d+) +/; $nfollow = $1; if($nfollow != ($ENUMBER+1)) { print(OUTFILE "$followuplist"); if($KEYWORD=~/$auto_regexp/o) { print(OUTFILE_AUTO "$followuplist"); } elsif ($KEYWORD=~/$auto_regexp2/o) { print(OUTFILE_NOAUTO "$followuplist"); } elsif($KEYWORD=~/$auto_regexp3/o) { print(OUTFILE_AUTO2 "$followuplist"); } else { print(OUTFILE_NOAUTO2 "$followuplist"); } } } else { print(OUTFILE "$followuplist"); if($KEYWORD=~/$auto_regexp/o) { print(OUTFILE_AUTO "$followuplist"); } elsif($KEYWORD=~/$auto_regexp2/o) { print(OUTFILE_NOAUTO "$followuplist"); } elsif($KEYWORD=~/$auto_regexp3/o) { print(OUTFILE_AUTO2 "$followuplist"); } else { print(OUTFILE_NOAUTO2 "$followuplist"); } } } } } } #=================================================================================== # at the end of the weekly listing put the monthly archive listings #=================================================================================== chdir( $htmldir ) || die "dolog can't chdir to $htmldir: $!\n"; opendir(HTMLARCHIVE, $htmldir ) || die "dolog can't open HTMLDIR: $!\n"; #=================================================================================== # Read and reverse sort the filenames as usual #=================================================================================== @html_array=reverse sort readdir( HTMLARCHIVE ); #=================================================================================== # Use only the filenames in the form xxxx_archive #=================================================================================== #Begin Y2K Fix @html_dirs_the1990s=reverse sort grep( /9..._archive$/, @html_array ); @html_dirs_newmillenium=reverse sort grep( /[0-8]..._archive$/, @html_array ); @html_dirs = (@html_dirs_newmillenium,@html_dirs_the1990s); #End Y2K Fix print OUTFILE "

  • \n"; print OUTFILE_AUTO "
    \n"; print OUTFILE_NOAUTO "
    \n"; print OUTFILE_AUTO2 "
    \n"; print OUTFILE_NOAUTO2 "
    \n"; print OUTFILE "\n"; print OUTFILE_AUTO "
    \n"; print OUTFILE_NOAUTO "
    \n"; print OUTFILE_AUTO2 "
    \n"; print OUTFILE_NOAUTO2 "
    \n"; foreach $html_archive (@html_dirs) { $entry_line = sprintf(qq{\n \n \n \n}, $html_archive."/logdir.html", @month[substr($html_archive, 2, 2 )], substr( $html_archive, 0, 2 ) ); print OUTFILE $entry_line; print OUTFILE_NOAUTO $entry_line; print OUTFILE_AUTO $entry_line; print OUTFILE_NOAUTO2 $entry_line; print OUTFILE_AUTO2 $entry_line; # Find the files that have been followed up open(LOGDIR,"<$htmldir$html_archive/logdir.html"); while(chomp($line=)){ if($line =~ /HREF=(\d{12}\.html)> *([^ ]*) /) { $fname=$1; $entry=$2; if($followed_file{$entry}) { $followed_file{$entry}="$html_archive/$fname"; # print "$entry $followed_file{$entry}\n"; } } } close(LOGDIR); } print OUTFILE "
    %s %s Archive\nEntire HALOG History Beam Accounting OnlyEnd of Run Only
    All EXCEPT Automatic EntriesStart Run Only
    Search Entries
    \n"; print OUTFILE_AUTO "\n"; print OUTFILE_NOAUTO "\n"; print OUTFILE_AUTO2 "\n"; print OUTFILE_NOAUTO2 "\n"; #Loop through all the followups foreach $newentry (sort keys %followed_ids) { $followed_id=$followed_ids{$newentry}; $followup_keyword=$followup_keywords{$newentry}; $followup_file=$followup_files{$newentry}; $followed_file=$followed_file{$followed_id}; # print "$newentry $followed_id $followup_file $followed_file\n"; # Ammend the old entry open(FOLLOWED,"<$htmldir$followed_file") || die "Can't open $htmldir$followed_file"; open(NEWTMP,">newtmp.html") || die "can't open newtmp.html"; while(chomp($line=)) { #Herbert's suggestion, add to each entry number, the keywords used for the # followup entries. To help the reader decide if he wants to see the followup. if($line =~ /keyword=/) { # print(NEWTMP qq{

    Followups: $newentry ($followup_keyword)

    \n}); print(NEWTMP qq{

    Followups:<\/h4>\n}); print(NEWTMP "$line\n"); last; # } elsif ($line =~ /^

    Followups: (.*)<\/h4>/) { } elsif ($line =~ /^

    Followups:<\/h4>(.*)<\/ul>/) { # print(NEWTMP qq{

    Followups: $1, $newentry ($followup_keyword)

    \n}); print(NEWTMP qq{

    Followups:<\/h4>$1
  • $followup_keyword\n}); last; } else { print(NEWTMP "$line\n"); } } while(chomp($line=)){ print(NEWTMP "$line\n"); } close(FOLLOWED); close(NEWTMP); system( "/bin/mv -f newtmp.html $htmldir$followed_file"); # Ammend the new entry open(FOLLOWUP,"<$htmldir$followup_file") || die "can't open $htmldir$followup_file"; open(NEWTMP,">newtmp.html") || die "can't open newtmp.html"; while(chomp($line=)) { if($line =~ /keyword=/) { print(NEWTMP qq{

    This entry is a followup to: $followed_id

    \n}); print(NEWTMP "$line\n"); last; } else { print(NEWTMP "$line\n"); } } while(chomp($line=)){ print(NEWTMP "$line\n"); } close(FOLLOWUP); close(NEWTMP); system( "/bin/mv -f newtmp.html $htmldir$followup_file"); } #Now we have complete cross referencing of the followups. We just need to #put in the apprpriate links at the tops of each entries. If an entry already has #followups, we need ot make sure we don't wreck them. # Later on we will add rebuilding of the logdirs closedir( HTMLARCHIVE ); &print_logdirtail(OUTFILE); &print_logdirtail(OUTFILE_AUTO); &print_logdirtail(OUTFILE_NOAUTO); &print_logdirtail(OUTFILE_AUTO2); &print_logdirtail(OUTFILE_NOAUTO2); close( OUTFILE ); close( OUTFILE_AUTO ); close( OUTFILE_NOAUTO ); close( OUTFILE_AUTO2 ); close( OUTFILE_NOAUTO2 ); #=================================================================================== # here we remove the old logdir.html and move the temporary filename logdir.new.html # into it's place. This should be a fast and hopefully, crashfree operations that # will make it almost unnoticable to users since it occurs so quickly. #=================================================================================== unlink( "logdir.html" ); rename( "logdir.new.html", "logdir.html" ); unlink( "logdir_auto.html" ); rename( "logdir_auto.new.html", "logdir_auto.html" ); unlink( "logdir_noauto.html" ); rename( "logdir_noauto.new.html", "logdir_noauto.html" ); unlink( "logdir_auto2.html" ); rename( "logdir_auto2.new.html", "logdir_auto2.html" ); unlink( "logdir_noauto2.html" ); rename( "logdir_noauto2.new.html", "logdir_noauto2.html" ); system( "/bin/chmod 777 $logdir.html" ); system( "/bin/chown adaq $logdir.html" ); #print "dolog is now finished\n"; closedir(TMPDIR); closedir(HTMLDIR); sleep(5); exit 0; #=================================================================================== # end of main PERL routine #=================================================================================== #=**********************************************************************=# #= =# #= month_update() =# #= Create a logdir.html file in the monthly archive that =# #= contains the logbook entries for that month. =# #= =# #=**********************************************************************=# sub month_update { $firstime = 0; #=================================================================================== # sort the html files directory while looking for valid log filenames #=================================================================================== opendir(HTMLDIR, $htmldir.$html_archive) || die "dolog can't open HTMLDIR: $!\n"; #=================================================================================== # do the usual reading of directory and sorting #=================================================================================== @html_array=reverse sort readdir( HTMLDIR ); #=================================================================================== # use only files that match the pattern #=================================================================================== @html_array=grep( /\d{12}\.html$/, @html_array ); chdir $htmldir.$html_archive || die "dolog - can't chdir to $htmldir: $!\n"; #=================================================================================== # remove the previous version of the temporary file logdir.new.html if it exists #=================================================================================== unlink( "logdir.new.html" ); unlink( "logdir_auto.new.html" ); unlink( "logdir_noauto.new.html" ); open( OUTFILE, ">logdir.new.html" ); open( OUTFILE_AUTO, ">logdir_auto.new.html" ); open( OUTFILE_NOAUTO, ">logdir_noauto.new.html" ); open( OUTFILE_AUTO2, ">logdir_auto2.new.html" ); open( OUTFILE_NOAUTO2, ">logdir_noauto2.new.html" ); &print_logdirmonthhead(OUTFILE,"Full Listing"); &print_logdirmonthhead(OUTFILE_AUTO,"Run Ends Only"); &print_logdirmonthhead(OUTFILE_AUTO2,"Run Starts Only"); &print_logdirmonthhead(OUTFILE_NOAUTO,"Accounting Only"); &print_logdirmonthhead(OUTFILE_NOAUTO2,"All EXCEPT Automatic Entries"); $oldday = None; #================================ # add PREV and NEXT to new files #================================ $tmpindex=0; #$lastfile = $html_array[$tmpindex]; foreach $html_filename (@html_array) { if ($html_filename == $lastfile) { #printf(" FOUND: $tmpindex $html_filename\n"); $endindex = $tmpindex+2; } #printf("@html_array[$tmpindex] $tmpindex\n"); $tmpindex++; } #$endindex = $tmpindex; #printf(" tmp=$tmpindex end=$endindex t=$tindex\n"); for ($tmpindex=0; $tmpindex<$endindex; $tmpindex++) #foreach $html_filename (@html_array) { #printf(" PREV/NEXT: $tmpindex $endindex\n"); $html_filename = @html_array[$tmpindex]; if ($tmpindex==0) { $NEXTFILE = "none"; $CURRFILE = @html_array[$tmpindex]; $PREVFILE = @html_array[$tmpindex+1]; } else { $NEXTFILE = @html_array[$tmpindex-1]; $CURRFILE = @html_array[$tmpindex]; $PREVFILE = @html_array[$tmpindex+1]; } #printf(" %s %s %s\n",$PREVFILE,$CURRFILE,$NEXTFILE); open(NEWTMP,">newtmp.html"); #print( "open newtmp.html\n"); open(TMPFILE,"$html_filename") || die "dolog can't open TMPFILE PREV/NEXT: $!\n"; #print( "open $html_filename for read\n"); while(chomp($line = )){ #printf( " %s\n",$line ); if ($line =~ /INDEX/) { #print("do nothing\n"); #printf( " %s\n",$line ); } elsif ($line =~ /PREV/) { #print("do nothing\n"); #printf( " %s\n",$line ); } elsif ($line =~ /NEXT/) { #print("do nothing\n"); #printf( " %s\n",$line ); } elsif (($line =~ /name=/) || ($line =~ /User name/)) {# Protect against printf(NEWTMP "%s\n",$line); # entries with while(chomp($line = )){ # INDEX, PREV, or NEXT in them printf(NEWTMP "%s\n",$line); } } else { printf(NEWTMP "%s\n",$line); } if ($line =~ /
    /) { #printf( " %s\n",$line ); # printf( NEWTMP "
  • Main INDEX\n"); # printf( NEWTMP "
  • Monthly INDEX\n",$html_archive); printf( NEWTMP "
  • Main INDEX\n"); printf( NEWTMP "
  • Monthly INDEX\n",$html_archive); if ($PREVFILE == "none"){ #printf(" prevfile is NONE *******\n"); } else { # printf( NEWTMP "
  • PREV\n", $html_archive,$PREVFILE); printf( NEWTMP "
  • PREV\n", $html_archive,$PREVFILE); } if ($NEXTFILE == "none"){ #printf(" nextfile is NONE *******\n"); }else { # printf( NEWTMP "
  • NEXT\n", $html_archive,$NEXTFILE); printf( NEWTMP "
  • NEXT\n", $html_archive,$NEXTFILE); } } } close(NEWTMP); system( "/bin/mv -f newtmp.html $html_filename"); system( "/bin/chmod 555 $html_filename*" ); system( "/bin/chown adaq $html_filename*" ); } # print( "Now back to the index file\n"); foreach $html_filename (@html_array) { $offset = index( $html_filename, $htmlSuffix, 0 ); $html_filename = substr( $html_filename, 0, $offset); #=================================================================================== # make the filename readible by the UNIX time commands #=================================================================================== @datetime[0] = 0; @datetime[1] = 0; @datetime[2] = substr( $html_filename, 6, 2 ); @datetime[3] = substr( $html_filename, 4, 2 ); @datetime[4] = substr( $html_filename, 2, 2 ) - 1; @datetime[5] = substr( $html_filename, 0, 2 ); $dtime = &timelocal( @datetime ); #=================================================================================== # figure out what day of week the filename is #=================================================================================== $thisday = (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday)[(localtime($dtime))[6]]; #Friday, Saturday)[(localtime($dtime+60*60-1))[6]]; #=================================================================================== # if the day of week is different that the previous, then print # the day of the week so that it's easier for people find an entry #=================================================================================== if ( $oldday ne $thisday ) { if ($firstime == 0) { $firstime = 1; } else { printf( OUTFILE "\n" ); printf( OUTFILE_AUTO "\n" ); printf( OUTFILE_NOAUTO "\n" ); printf( OUTFILE_AUTO2 "\n" ); printf( OUTFILE_NOAUTO2 "\n" ); } $dayheader = "

    $thisday

    \n
    \n";
    	    print OUTFILE $dayheader;
    	    print OUTFILE_AUTO $dayheader;
    	    print OUTFILE_NOAUTO $dayheader;
    	    print OUTFILE_AUTO2 $dayheader;
    	    print OUTFILE_NOAUTO2 $dayheader;
    
                $oldday = $thisday;
    	}
    
            $html_date=substr( $html_filename, 2, 2 ) . "/" .
                       substr( $html_filename, 4, 2 ) . "/" .
                       substr( $html_filename, 0, 2 );
    
            $html_shift=substr( $html_filename, 6, 2 ) . ":" .
                       substr( $html_filename, 8, 2 );# . ":" .
    #                   substr( $html_filename, 10, 2 );
    
    # open html file and retrieve the keyword and user name from the file
    	$KEYWORD="no_key";
    	$NAMWORD="no_name";
    	$ENUMBER="0";
            $followuplist = "";
    	open(TMPFILE,"$html_filename$htmlSuffix") || die "dolog can't open TMPFILE: $!\n";
    	while(chomp($line = )){
    		if ($line =~ /keyword=/) {
    		    $tempkey="$'" if $line =~ /keyword=/;
    		    $KEYWORD = "$`" if $tempkey =~ /
    /; $KEYWORD = "$`" if $tempkey =~ /

    /; $KEYWORD = "$`" if $tempkey =~ /

    /; last; # } elsif ($line =~ /^

    Followups: (.*)<\/h4>/) { } elsif ($line =~ /^

    Followups:<\/h4>(.*)$/) { $followuplist = $1; } if ($line =~ /User name/) { $tempkey="$'" if $line =~ /User name/; $NAMWORD = "$`" if $tempkey =~ /<\/h4>/; } if ($line =~ /Entry number/) { @enumber = split(' ',$line); @enumber = split('<',$enumber[2]); $ENUMBER = $enumber[0]; } } close(TMPFILE); $entry_line=sprintf("
  • %6s %s %s %-15.13s %s\n", $html_filename, $ENUMBER, $html_date, $html_shift, $NAMWORD, $KEYWORD); print OUTFILE $entry_line; if($KEYWORD=~/$auto_regexp/o) { print OUTFILE_AUTO $entry_line; } elsif($KEYWORD=~/$auto_regexp2/o) { print OUTFILE_NOAUTO $entry_line; } elsif($KEYWORD=~/$auto_regexp3/o) { print OUTFILE_AUTO2 $entry_line; } else { print OUTFILE_NOAUTO2 $entry_line; } if($followuplist) { # $followuplist =~ s/a>,
  • $followuplist"); print(OUTFILE "$followuplist"); if($KEYWORD=~/$auto_regexp/o) { print(OUTFILE_AUTO "$followuplist"); } elsif($KEYWORD=~/$auto_regexp2/o) { print(OUTFILE_NOAUTO "$followuplist"); } elsif($KEYWORD=~/$auto_regexp3/o) { print(OUTFILE_AUTO2 "$followuplist"); } else { print(OUTFILE_NOAUTO2 "$followuplist"); } } } #=================================================================================== # remove the logdir.html and replace it with the new one. Similar to the # weekly listing. #=================================================================================== unlink( "logdir.html" ); rename( "logdir.new.html", "logdir.html" ); unlink( "logdir_auto.html" ); rename( "logdir_auto.new.html", "logdir_auto.html" ); unlink( "logdir_noauto.html" ); rename( "logdir_noauto.new.html", "logdir_noauto.html" ); unlink( "logdir_auto2.html" ); rename( "logdir_auto2.new.html", "logdir_auto2.html" ); unlink( "logdir_noauto2.html" ); rename( "logdir_noauto2.new.html", "logdir_noauto2.html" ); system( "/bin/chmod 777 $logdir.html" ); system( "/bin/chown adaq $logdir.html" ); printf( OUTFILE "\n" ); printf( OUTFILE_AUTO "\n" ); printf( OUTFILE_NOAUTO "\n" ); printf( OUTFILE_AUTO2 "\n" ); printf( OUTFILE_NOAUTO2 "\n" ); &print_logdirtail(OUTFILE); close( OUTFILE ); close( OUTFILE_AUTO ); close( OUTFILE_NOAUTO ); close( OUTFILE_AUTO2 ); close( OUTFILE_NOAUTO2 ); closedir(HTMLDIR); } #=**********************************************************************=# #= =# #= =# #=**********************************************************************=# sub update_html { #======================================================================= # open the directory. If you can't then it doesn't exist so make it. #======================================================================= $archiveDir = substr( $root_filename, 0, 4 ) . $archiveSuffix . "/"; opendir( ARCHIVEDIR, $htmldir . $archiveDir ) || mkdir( $htmldir . $archiveDir, 0755 ); #======================================================================= # check if the file is a followup to a previous entry #======================================================================= open(SCAN,"<$tmpdir$root_filename.html") || die "dolog can't open $!\n"; $html_date=substr( $root_filename, 2, 2 ) . "/" . substr( $root_filename, 4, 2 ) . "/" . substr( $root_filename, 0, 2 ); $html_shift=substr( $root_filename, 6, 2 ) . ":" . substr( $root_filename, 8, 2 );# . ":" . # substr( $root_filename, 10, 2 ); $KEYWORD="no_key"; $NAMWORD="no_name"; $ENUMBER="0"; $followsup_entry=0; while(chomp($line = )){ # Need to take only first number shown here if ($line =~ //) { $followsup_entry=$1; } elsif ($line =~ />Entry number (.*)/; } elsif ($line =~ /keyword=/) { $tempkey="$'" if $line =~ /keyword=/; $KEYWORD = "$`" if $tempkey =~ /
    /; $KEYWORD = "$`" if $tempkey =~ /

    /; $KEYWORD = "$`" if $tempkey =~ /

    /; last; } } close(SCAN); if($followsup_entry) { # print "Entry $entry is a followup to $followsup_entry\n"; $followup_files{$entry}="$archiveDir$root_filename.html"; $followed_ids{$entry}=$followsup_entry; $followed_file{$followsup_entry}="x"; $followup_keywords{$entry}=sprintf("%6s %s %s %-15.13s %s", $entry, $html_date, $html_shift,$NAMWORD,$KEYWORD); } #======================================================================= # move html file into final html archive directory #======================================================================= system( "/bin/mv $tmpdir$root_filename.html $htmldir$archiveDir" ); system( "/bin/mv $tmpdir$root_filename*.gif $htmldir$archiveDir" ); system( "/bin/chmod 755 $htmldir$archiveDir/$root_filename*" ); # system( "/bin/chown webmgr $htmldir$archiveDir/$root_filename*" ); system( "/bin/chown adaq $htmldir$archiveDir/$root_filename*" ); #print( "--> Mark:: 3\n" ); } #=**********************************************************************=# #= =# #= =# #=**********************************************************************=# sub reverse { $b cmp $a; } sub print_logdirmonthhead { my $fh = shift(@_); my $type = shift(@_); print $fh "\n"; print $fh "\n"; print $fh "$LOGTITLE Logbook\n"; print $fh "\n"; printf( $fh "

    Jefferson Lab $LOGTITLE Logbook for %s %s - %s

    \n", @month[substr($html_archive, 2, 2 )], substr( $html_archive, 0, 2 ),$type); print $fh "
    \n"; # printf( $fh "
  • Main INDEX\n"); print $fh "
  • Main INDEX\n"; } sub print_logdirhead { my $fh = shift(@_); my $type = shift(@_); print $fh "\n"; print $fh "\n"; print $fh "$LOGTITLE Logbook\n"; print $fh "\n"; print $fh "

    Jefferson Lab $LOGTITLE Logbook - $type

    \n"; # print $fh "

    #Preview $logbook Entries

    \n"; print $fh "

    halog FAQ's+HOWTO

    \n"; print $fh "
    \n"; print $fh "Logbook:\n"; print $fh qq{\n}; print $fh qq{}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{
    Scrollable logbookBeam Accounting OnlyAll EXCEPT Automatic EntriesOld Halog Archives
    Preview $logbook EntriesRun Ends OnlyRun Starts OnlySearch Entries
    \n}; print $fh qq{

    \n}; print $fh "Other Logbooks:\n"; print $fh qq{\n}; print $fh qq{}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{
    Operations: ELOGCryo: CLOGSoftware: SLOGPol Src: POLOG
    FEL: FLOGHall-A: HALOGHall-B: HBLOGHall-C: HCLOG
    \n}; print $fh qq{

    \n}; print $fh qq{Other Links:\n}; print $fh qq{\n}; print $fh qq{}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{
    PD Shift Plans MCC Crew Chief Shift Summs Short Term Schedule
    Experiment Schedule CEBAF status screen Ops Documentation
    \n}; #printf( $fh "

  • Scrollable $LOGTITLE\n"); #printf( $fh "

    Other Links:

    \n" ); #printf( $fh "

    \n" ); #printf( $fh " hclog FAQ's+HOWTO \n" ); #printf( $fh "

    Other Links

    \n" ); #printf( $fh "
  • CEBAF status screen
  • \n" ); #printf( $fh "
  • Experiment Schedule
  • \n" ); #printf( $fh "
  • MCC short term schedule
  • \n" ); #printf( $fh qq{
  • Beam Information (not yet operational)
  • \n} ); #printf( $fh "

    \n" ); #printf( $fh "
    \n" ); } sub print_logdirtail { my $fh = shift(@_); print $fh "
    \n"; print $fh "This file generated by $0 version $SCRIPT_VERSION
    \n"; print $fh "
    If you have any comments or problems, please contact:
    \n"; print $fh "Robert Michaels
    \n"; print $fh "rom\@jlab.org
    \n"; print $fh "(757) 269-7410

    \n"; print $fh "\n"; }