#!/usr/local/bin/perl
# 
# $Header: otrace.pl 23-nov-2006.06:52:12 manosing Exp $
#
# otrace.pl
# 
# Copyright (c) 2006, Oracle. All rights reserved.  
#
#    NAME
#      otrace.pl - <one-line expansion of the name>
#
#    DESCRIPTION
#      <collects otrace data files>
#
#    NOTES
#      <other useful comments, qualifications, etc.>
#
#    MODIFIED   (MM/DD/YY)
#    manosing    10/10/06 - Creation
# 

use strict ;
  
  require "$ENV{EMDROOT}/sysman/admin/scripts/db/esaDbUtils.pl";
  require "$ENV{EMDROOT}/sysman/admin/scripts/db/esaUtils.pl";
  my $oracleHome = $ENV{EM_TARGET_ORACLE_HOME};
  my $maxRows = $ENV{'OTRACE'};
   my $limit = 0 ;
#  $maxRows =1; # for  now 
  my $path = qq($oracleHome/otrace/admin);
  if($^O eq "MSWin32"){
    $path =~s /\//\\/g;
  }

  opendir(DIRHANDLE,$path)||exit(0);
  my @content = grep /^.*\.dat$/,readdir(DIRHANDLE);

  if($maxRows == 0 ){
      exit(0);
  }
  foreach(@content){

      if($maxRows!=-1 && $limit == $maxRows)
      {
          exit(0);
      }
      print "em_result=otrace|$_\n";
      $limit++;

  }
   
  
  
      
  
 
