#!/usr/bin/perl 

# I Russ Welti wrote this at one point as a quick diagnostic aid
# because we were getting chopped off and garbled lines in cnss.fing

# I now believe the problem was in the transmission (ncftpget) and
# not the data file itself.

# To my knowledge this script is not called or used by cron.

# Russ 5/2013



unless(open(FING,"</ftp/pub/cnss/cnss.fing")) { die "could not open cnss.fing"; }

unless(open(BAD,">/ftp/pub/cnss//cnss.badlines")) { die "could not open cnss.badlines"; }




print "checking cnns.fing for bad lines at ".  localtime(time)."\n";

$line=1;

while(<FING>) {

  if( (length($_) < 25) ||
      (substr($_,"2002") < 0) ) {

    print BAD "\n\n\n------------------------------------------------
at ".localtime(time)." bad line number $line:\n";
    print BAD $_;

    chomp($_);

    if($_ eq "A") {

      print BAD "\n\nHere is the bad line\'s region: check for dups:\n\n";

      close(FING);
      close(BAD);

      $n_lines=`cat /wave/ftp/pub/cnss/cnss.fing | wc -l`;
      $tailAmt=($n_lines-$line)*2;
      $cmd="tail -".$tailAmt." /wave/ftp/pub/cnss/cnss.fing >> /users/russ/cnss.badlines";
      system("echo $cmd >> /users/russ/cnss.badlines");
      system($cmd);
      exit(0);
    }
  }
  $line++;
}

print "in $line lines, saw no obvious errors\n";
exit(0);
