#
# program name autoburt.pl
#
# Function. Called by cron at regular times in the day. This script
# creates a directory for today (if it doesnt exist) under the path
# CDS_ROOT/cds/lho/burt/year/month/day. It then searches for autoBurt.req
# files under the CDS_ROOT/cds/lho/target directory.
#
# It then launches burt, using all autoBurt.req files and outputing
# the snapshot file under todays directory
#
# 00 19Aug2000   D.Barker  first release
# 01 31Aug2000   D.Barker  Make generic to run on both sites.
# 02 23May2002   D.Barker  Add 40m
#

$DEBUG = 0;
$CHECK_SNAPSHOT_FILE = 1;
$TEMPFILE = "/tmp/autoburt";


@knownproblems = ( 
"h0daqepics",
"h0ee0",
"h0ee1",
"h0ee2",
"h0ee3",
"h0sandbox0",
"h0sandbox1",
"h0sandbox2",
"h0sandbox3",
"tpman",);



{

  # Find what site we are on
  whereAreWe();

  if ($site eq "lho") {
  } else {
  }

  if ($site eq "lho") {
    $sitepath = "/cvs/cds/lho";
    $autoburtpath = "$sitepath/burt/autoburt";
    $epicsbin = "/opt/CDS/a/epics/release/r3.12.2.baja47.tornado/extensions/bin/
solaris";
    $pathlength = 20;
    if($DEBUG) { print "settings for hanford\n";}
    if($DEBUG) { print "sitepath $sitepath\n";}
    if($DEBUG) { print "autoburtpath $autoburtpath\n";}
    if($DEBUG) { print "epicsbin $epicsbin\n";}
  } elsif ($site eq "40m") {
    $sitepath = "/cvs/cds/caltech";
    $autoburtpath = "$sitepath/burt/autoburt";
    $epicsbin = "/cvs/cds/epics/extensions";
    $pathlength = 24;
    if($DEBUG) { print "settings for Caltech 40m\n";}
    if($DEBUG) { print "sitepath $sitepath\n";}
    if($DEBUG) { print "autoburtpath $autoburtpath\n";}
    if($DEBUG) { print "epicsbin $epicsbin\n";}
  
  } elsif  ($site eq "llo"){
    #$sitepath = "/opt/LLO/g/cvs/cds/llo";
    $sitepath = "/cvs/cds/llo";
    $autoburtpath = "$sitepath/burt/autoburt";
    $epicsbin = "/opt/LLO/a/epics/release/r3.12.2/extensions/bin/solaris";
    $pathlength = 20;
    if($DEBUG) { print "settings for louisiana\n";}
    if($DEBUG) { print "sitepath $sitepath\n";}
    if($DEBUG) { print "autoburtpath $autoburtpath\n";}
    if($DEBUG) { print "epicsbin $epicsbin\n";}

  } elsif ($site eq "kami") {
    $sitepath = "/cvs/cds/kami";
    $autoburtpath = "$sitepath/burt/autoburt";
    $epicsbin = "/opt/epics-3.14.10-RC2-i386/base/bin/linux-x86/";
    $pathlength = 21;
    if($DEBUG) { print "settings for Kamioka CLIO\n";}
    if($DEBUG) { print "sitepath $sitepath\n";}
    if($DEBUG) { print "autoburtpath $autoburtpath\n";}
    if($DEBUG) { print "epicsbin $epicsbin\n";}
  
  } else {
    die "Dont know where we are\n";
  }

  # get current time/date
  $datetime = returnTimeStamp();
  $snapfile = "shapshot."."$datetime";
  print $snapfile."\n";

  # remove existing /cvs/cds/lho/burt/autoburt/.requestfilelist
  $command = "/bin/rm -rf $autoburtpath/.requestfilelist";
  system($command);

  # find all /cvs/cds/lho/target/*/autoBurt.req files
  $command = "/bin/ls $sitepath/target/*/autoBurt.req > $autoburtpath/.requestfi
lelist";
  system($command);

  # open /cvs/cds/lho/burt/autoburt/.requestfilelist
  open(REQLIST,"$autoburtpath/.requestfilelist")||die "cannot open file $autobur
tpath/.requestfilelist\n";


  # create the snapshot directory for this run
  # path is $autoburt/snapshots/year/month/day/hour

  $yearpath = $autoburtpath."/snapshots/".$thisyear;
  # print "scanning for path $yearpath\n";

  if (!-e $yearpath) {
    die "ERROR: Year directory $yearpath does not exist\n";
  }

  $monthpath = $yearpath."/$thismonth";
  print "scanning for path $monthpath\n";
  if (!-e $monthpath) {
    print "Creating month directory $monthpath\n";
    $command = "/bin/mkdir $monthpath";
    system ($command);
  }

  $datepath = $monthpath."/$thisdate";
  print "scanning for path $datepath\n";
  if (!-e $datepath) {
    print "Creating month directory $datepath\n";
    $command = "/bin/mkdir $datepath";
    system ($command);
  }

  $hourpath = $datepath."/$thishour:$thismin";
  if (!-e $hourpath) {
    print "Creating hour directory $hourpath\n";
    $command = "/bin/mkdir $hourpath";
    system ($command);
  } else {
    die " Warning: \n      Directory $hourpath \n      already exists! \n      A
borting burt\n";
  }

  # loop over target list, performing burt backup on each one
  while ($targetreqfile = <REQLIST>) {
    chomp $targetreqfile;
    # get target name, strip off /cvs/cds/lho/target/ from file path
    $targetname = substr $targetreqfile,$pathlength;
    ($targetname,$rest) = split /\//,$targetname,2;
    print "----------------------------------------------------\n";
    print "Target $targetname\n";

    # remove targetname.log file in /cvs/cds/lho/burt/autoburt/logs
    $command = "/bin/rm -rf $autoburtpath/logs/$targetname.log";
    system ($command);

    # Perform the burt

    $command = "$epicsbin/burtrb -f $targetreqfile -o $hourpath/$targetname.snap
 -v -l $autoburtpath/logs/$targetname.log -c $targetname";
    system($command);

    if ($CHECK_SNAPSHOT_FILE) {
      # check the snapshot file against the request file
      # do number of lines check, snapshot file  = request file + 11
      
      $sfile = $hourpath."/".$targetname.".snap";
      print "Opening snapshot file $sfile \n";
      open(TEMP,"<".$sfile)||die "Cannot open $sfile \n";
      # loop down to the end of header
      while (($line=<TEMP>) &&($line !~ "End BURT header")) {
        ;
      }
      
      # next line is first data line
      $snapwordcount=0;
      while($line=<TEMP>) {
        $snapwordcount++;
      }

      close TEMP;


      $command = "/bin/rm -rf $TEMPFILE";
      system($command);
      $command = "/usr/bin/wc $targetreqfile > $TEMPFILE";
      system($command);
      open(TEMP,$TEMPFILE)||die "Cannot open temp file $TEMPFILE \n";
      $line = <TEMP>;
      chomp $line;
      ($reqwordcount,$rest) = split " ",$line,2;
      
      print "Request File $reqwordcount lines, SnapShot File $snapwordcount line
s\n";
      if ($snapwordcount != $reqwordcount ) {
        $found = 0;
        foreach $name (@knownproblems) {
          if ($targetname eq $name) {
            $found=1;
            print "WARNING: Target $targetname Snapshot file inconsistent with R
equest file\n";
          }
        }
        if (!$found) {
          print "!!!  ERROR !!! ";
          print "Target $targetname Snapshot file inconsistent with Request file
\n";
        }


      }
      
      
    
    }
  }
  close REQLIST;


  # Clean up work.

  # for burt snapshots which are more than a month old, remove all hourly
  # backups except for the 04168\.hr and 16hr.

  cleanupfiles();


}


# ----------------------------------------------------------------------
#
# Subroutine returnTimeStamp()
#
# Returns the current time stamp as a string
#
# ----------------------------------------------------------------------
sub returnTimeStamp {

  @timestamp = localtime(time);
  $thisday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[$timestamp[6]];
  $thismonth = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[$timestamp[4]];
  # Y2k stuff
  # Year 2000 defined as $timestamp[5] = 100
  if($timestamp[5]> 99) {
    $timestamp[5] = $timestamp[5] - 100;
    $thisyear = "20".$timestamp[5];
  } else {
    $thisyear = "19".$timestamp[5];
  }
  if ($timestamp[2] < 10) {
    $thishour = "0".$timestamp[2];
  } else {
    $thishour = $timestamp[2];
  }
  if ($timestamp[1] < 10) {
    $thismin = "0".$timestamp[1];
  } else {
    $thismin = $timestamp[1];
  }
  if ($timestamp[0] < 10) {
    $thissec = "0".$timestamp[0];
  } else {
    $thissec = $timestamp[0];
  }

  $thisdate = $timestamp[3];
  if ($thisdate < 10) {
    $thisdate = "0".$thisdate;
  }

  return "$thisday$thisdate$thismonth$thisyear-$thishour:$thismin:$thissec";


}

# ----------------------------------------------------------------------
#
# Subroutine cleanupfiles()
#
# Go back one month and remove all hourly backups except hours 04 and 16
#
# ----------------------------------------------------------------------
sub cleanupfiles {

  print "cleanupfiles: TBD\n";


  return;
}


# ----------------------------------------------------------------------
#
# Subroutine whereAreWe()
#
# find out what site we are on
#
# ----------------------------------------------------------------------
sub whereAreWe {

   $temp = "./tempfile";

   # Find out which site we are on, using IP address of this workstation
   $command = "/bin/rm -rf $temp";
   system($command);

   $command = "/usr/sbin/ifconfig -a > $temp";
   system($command);

   open(TEMP,$temp) || die "Cannot open file $temp\n";
   $site = "undefined";
   while ($line = <TEMP>) {
     if ($line =~ /10\.1\./) {
       $site = "lho";
     } elsif ($line =~ /10\.100\./) {
       $site = "llo";
     } elsif ($line =~ /131\.215\./) {
       $site = "40m";
     } elsif ($line =~ /192\.168\.11\./) {
       $site = "kami";
     }
   }
   if ($site eq "undefined") {
     die "Cannot Determine Which LIGO Observatory this is\n";
   }
   print "Site is $site\n";

}

CLIO/Tasks/DigitalControl/RTCSetupMemo/autoburt (last edited 2010-04-22 11:53:57 by OsamuMiyakawa)