Advertisement
Guest User

GarciaPL

a guest
Aug 21st, 2013
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 11.03 KB | None | 0 0
  1. use Date::Calc;
  2. use Spreadsheet::WriteExcel;
  3. use Spreadsheet::WriteExcel::Utility;
  4.  
  5. sub help_syntax {
  6.     print "\nHelp Syntax :\n\n";
  7.     print "Backuped FileSystems and Oracle (default) -> perl script_name.pl\n";
  8.     print "Backuped FileSystems and Oracle in .xls format -> perl script_name.pl --xls\n";
  9.     print "Backuped FileSystems -> perl script_name.pl --FS\n";
  10.     print "Backuped FileSystems in format .xls -> perl script_name.pl --FS --xls\n";
  11.     print "Backuped Oracle -> perl script_name.pl --Oracle\n";
  12.     print "Backuped Oracle in format .xls -> perl script_name.pl --Oracle --xls\n\n";
  13. }
  14.  
  15. $boolean_only_FS=0;
  16. $boolean_only_Oracle=0;
  17. $boolean_only_xls=0;
  18.  
  19. if ( scalar(@ARGV) > 2 )
  20. {
  21.     print "Numer of arguments is incorrect (max 2)\n";
  22.     &help_syntax;
  23.     exit;
  24. }
  25.  
  26. my $workbook;
  27. my $worksheet;
  28. my ($x,$y)=(0,0);
  29. my $glowny_licznik=0;
  30.  
  31. sub xls_function {
  32.  
  33.     $workbook = Spreadsheet::WriteExcel->new('output.xls');
  34.     $worksheet = $workbook->add_worksheet('Backups');
  35.     $format = $workbook->add_format();
  36.     $format->set_bold();
  37.     $format->set_align('center');
  38.     $format->set_fg_color('grey');
  39.     $format->set_size(12);
  40.     $format->set_color('black');
  41.     $worksheet->set_column(0,0,20);
  42.     $worksheet->set_column(1,1,30);
  43.     $worksheet->set_column(2,2,7);
  44.     $worksheet->set_column(3,3,40);
  45.     $worksheet->set_column(4,4,13);
  46.     $worksheet->set_column(5,5,15);
  47.     $worksheet->set_column(6,6,18);
  48.     $worksheet->write(0,0,"Session",$format);
  49.     $worksheet->write(0,1,"Server",$format);
  50.     $worksheet->write(0,2,"Type",$format);
  51.     $worksheet->write(0,3,"Backuped filesystems",$format);
  52.     $worksheet->write(0,4,"Time start",$format);
  53.     $worksheet->write(0,5,"Duration",$format);
  54.     $worksheet->write(0,6,"Data GB",$format);
  55. }
  56.  
  57. @lista_argumentow;
  58. foreach (@ARGV) {
  59.     push(@lista_argumentow,$_);
  60. }
  61.  
  62. if ( @lista_argumentow[0] eq "--help" || @lista_argumentow[0] eq "-help" || @lista_argumentow[0] eq "/h" || @lista_argumentow[0] eq "help" )
  63. {
  64.     &help_syntax;
  65.     exit;
  66. }
  67. elsif ( @lista_argumentow[0] eq "--xls" and @lista_argumentow[1] eq "" )
  68. {
  69.     $boolean_only_xls=1;
  70.     $boolean_only_FS=1;
  71.     $boolean_only_Oracle=1;
  72.     &xls_function;
  73. }
  74. elsif ( @lista_argumentow[0] eq "--FS" and @lista_argumentow[1] eq "--xls" )
  75. {
  76.     $boolean_only_xls=1;
  77.     $boolean_only_FS=1;
  78.    
  79.     &xls_function;
  80. }
  81. elsif ( @lista_argumentow[0] eq "--Oracle" and @lista_argumentow[1] eq "--xls" )
  82. {
  83.     $boolean_only_xls=1;
  84.     $boolean_only_Oracle=1;
  85.    
  86.     &xls_function;
  87. }
  88. elsif ( @lista_argumentow[0] eq "--FS" and @lista_argumentow[1] eq "" )
  89. {
  90.     $boolean_only_FS=1;
  91. }
  92. elsif ( @lista_argumentow[0] eq "--Oracle" and @lista_argumentow[1] eq "" )
  93. {
  94.     $boolean_only_Oracle=1;
  95. }
  96. elsif ( scalar(@ARGV) eq 0 )
  97. {
  98.     $boolean_only_Oracle=1;
  99.     $boolean_only_FS=1;
  100. }
  101. else
  102. {
  103.     &help_syntax;
  104.     exit;
  105. }
  106.  
  107. ###################################################################################
  108.  
  109. $omniback_path="D:/HP/OmniBack/bin";
  110.  
  111. chdir($omniback_path) or die "Cannot open path $omniback_path\n";
  112.  
  113. if (-e "omnirpt.exe" ) {
  114.     print "Found omnirpt.exe\n";
  115. }
  116. else {
  117.     print "File omnirpt.exe does not exist. Exit program.\n";
  118.     exit;
  119. }
  120.  
  121. $lista_sesji_command=`omnirpt.exe -report list_sessions -timeframe 24 24`;
  122.  
  123. open FILE, ">session_list.txt" or die $!; #print list of session for Oracle and FileSystem
  124. print FILE $lista_sesji_command;
  125. close FILE;
  126. print "Created session list in file session_list.txt\n";
  127.  
  128. if (-e "session_list.txt")
  129. {
  130. open (CHECKBOOK, "<session_list.txt");
  131. open (PLIK_WYNIKOWY, '>output.txt');
  132.  
  133. $count = 0;
  134. $count_oracle=0;
  135.  
  136. while ($record = <CHECKBOOK>) {
  137.         @tokens = split(/\s+/, $record);
  138.         my $boolean = 0;
  139.         $count_oracle=0;
  140.         $count=$count+1;
  141.         foreach my $token (@tokens) {
  142.             if ( @tokens[2] ne "Oracle8" and $boolean_only_FS eq 1)
  143.             {
  144.                 if ( $boolean eq 0 )
  145.                 {
  146.                     if( @tokens[15] ne "Errors" )
  147.                     {
  148.                         if( @tokens[15] ne "" )
  149.                         {
  150.                             print "\n----FileSystem----\n";
  151.                             print "Session : ",@tokens[2],"\n";
  152.                             print "Time start : ",@tokens[6],"\n";
  153.                             print "Duration : ",@tokens[8],"\n";
  154.                             print "Data GB : ",@tokens[9],"GB\n";
  155.                             print "SessionID : ",@tokens[15],"\n";
  156.                            
  157.                             $temp_session_ID=@tokens[15];
  158.                             $session_objects=`omnirpt.exe -report session_objects -session $temp_session_ID`;
  159.                             $licz=0;
  160.                             $temp_host;
  161.                             $temp_host2;
  162.                             $boolean_session=1;
  163.                             $flaga_rowne=1;
  164.                             $flaga_nierowne=1;
  165.                            
  166.                             @tokens_session_objects = split(/\s+/, $session_objects);
  167.                             foreach my $token_session (@tokens_session_objects) {
  168.                                 $licz=$licz+1;
  169.                                 $temp_host=@tokens_session_objects[$licz];
  170.                                
  171.                                 if( $token_session =~ m/FileSystem/)
  172.                                 {
  173.                                         $glowny_licznik = $glowny_licznik + 1;
  174.                                
  175.                                         if ( $boolean_session )
  176.                                         {
  177.                                             $temp_host2=$temp_host;
  178.                                         }
  179.  
  180.                                         ####################################################################################                           
  181.  
  182.                                         if ( $boolean_session )
  183.                                         {
  184.                                             print PLIK_WYNIKOWY @tokens[2],"    ";          #Session (once)
  185.                                            
  186.                                             if ( $boolean_only_xls )
  187.                                             {
  188.                                                 $worksheet->write($glowny_licznik,0,@tokens[2]);
  189.                                             }
  190.                                         }
  191.                                         if ( $boolean_session )
  192.                                         {
  193.                                             print PLIK_WYNIKOWY "   ",@tokens_session_objects[$licz],"  ";      #host
  194.                                            
  195.                                             if ( $boolean_only_xls )
  196.                                             {
  197.                                                 $worksheet->write($glowny_licznik,1,@tokens_session_objects[$licz]);
  198.                                             }
  199.                                         }
  200.                                         else
  201.                                         {
  202.                                             print PLIK_WYNIKOWY "       ",@tokens_session_objects[$licz],"  ";      #host
  203.                                            
  204.                                             if ( $boolean_only_xls )
  205.                                             {
  206.                                                 $worksheet->write($glowny_licznik,1,@tokens_session_objects[$licz]);
  207.                                             }
  208.                                         }
  209.                                        
  210.                                         if ( @tokens_session_objects[$licz] eq $temp_host2 and $flaga_rowne == 1)   #hosts name are the same
  211.                                         {
  212.                                             if ( $boolean_session )
  213.                                             {
  214.                                                 print PLIK_WYNIKOWY "FS","      ";     
  215.                                                
  216.                                                 if ( $boolean_only_xls )
  217.                                                 {
  218.                                                     $worksheet->write($glowny_licznik,2,"FS");
  219.                                                 }
  220.                                                
  221.                                             }
  222.                                         }
  223.                                         if ( @tokens_session_objects[$licz] ne $temp_host2 and $flaga_nierowne == 1) #different host names
  224.                                         {
  225.                                             if ( $boolean_session )
  226.                                             {
  227.                                                 print PLIK_WYNIKOWY "FS","      "; 
  228.                                                
  229.                                                 if ( $boolean_only_xls )
  230.                                                 {
  231.                                                     $worksheet->write($glowny_licznik,2,"FS");
  232.                                                 }
  233.                                             }
  234.                                         }
  235.                                        
  236.                                        
  237.                                         if ( $boolean_session )
  238.                                         {
  239.                                             print PLIK_WYNIKOWY @tokens_session_objects[$licz+1],"      ";  #Backuped filesystems
  240.                                            
  241.                                             if ( $boolean_only_xls )
  242.                                             {
  243.                                                 $worksheet->write($glowny_licznik,3,@tokens_session_objects[$licz+1]);
  244.                                             }
  245.                                         }
  246.                                         else
  247.                                         {
  248.                                             print PLIK_WYNIKOWY @tokens_session_objects[$licz+1],"\n";  #Backuped filesystems
  249.                                            
  250.                                             if ( $boolean_only_xls )
  251.                                             {
  252.                                                 $worksheet->write($glowny_licznik,3,@tokens_session_objects[$licz+1]);
  253.                                             }
  254.                                         }
  255.                                        
  256.                                        
  257.                                         if ( @tokens_session_objects[$licz] eq $temp_host2 and $flaga_rowne == 1)   #host names are the same
  258.                                         {
  259.                                             if ( $boolean_session )
  260.                                             {
  261.                                                 print PLIK_WYNIKOWY @tokens[6],"    ";                          #Time start (once)
  262.                                                 print PLIK_WYNIKOWY @tokens[8],"    ";                          #Duration (once)
  263.                                                 print PLIK_WYNIKOWY @tokens[9],"GB\n";                          #Data GB (once)
  264.                                                 $boolean_session=0;
  265.                                                
  266.                                                 if ( $boolean_only_xls )
  267.                                                 {
  268.                                                     $worksheet->write($glowny_licznik,4,@tokens[6]);
  269.                                                     $worksheet->write($glowny_licznik,5,@tokens[8]);
  270.                                                     $worksheet->write($glowny_licznik,6,"@tokens[9] GB");
  271.                                                 }
  272.                                             }
  273.                                        
  274.                                             $flaga_rowne=0;
  275.                                             $flaga_nierowne=1;
  276.                                         }
  277.                                         if ( @tokens_session_objects[$licz] ne $temp_host2 and $flaga_nierowne == 1) #different host names
  278.                                         {
  279.                                             if ( $boolean_session )
  280.                                             {
  281.                                                 print PLIK_WYNIKOWY @tokens[6],"    ";                          #Time start (once)
  282.                                                 print PLIK_WYNIKOWY @tokens[8],"    ";                          #Duration (once)
  283.                                                 print PLIK_WYNIKOWY @tokens[9],"GB\n";                          #Data GB (once)
  284.                                                 $boolean_session=0;
  285.                                                
  286.                                                 if ( $boolean_only_xls )
  287.                                                 {
  288.                                                     $worksheet->write($glowny_licznik,4,@tokens[6]);
  289.                                                     $worksheet->write($glowny_licznik,5,@tokens[8]);
  290.                                                     $worksheet->write($glowny_licznik,6,"@tokens[9] GB");
  291.                                                 }
  292.                                             }
  293.                                            
  294.                                             $flaga_nierowne=0;
  295.                                             $flaga_rowne=1;
  296.                                         }
  297.                                        
  298.                                         $temp_host=@tokens_session_objects[$licz];
  299.                                         $temp_host2=@tokens_session_objects[$licz];
  300.                                 }
  301.                             }
  302.                             print "\n";
  303.                             $boolean = 1;
  304.                         }
  305.                     }
  306.                 }
  307.             }
  308.             elsif ( $boolean_only_Oracle eq 1 ) #in the session found Oracle8
  309.             {
  310.                 $temp_session_oracle=@tokens[16];                   #sessionID
  311.                 $oracle=`omnidb.exe -session $temp_session_oracle`;
  312.                 @tokens_oracle8 = split(/\s+/, $oracle);
  313.                 my $boolean_check=1;
  314.  
  315.                 foreach my $token_oracle (@tokens_oracle8) {
  316.  
  317.                     if( $token_oracle =~ m/.dbf/ and $boolean_check eq 1) #one host - one SID
  318.                     {
  319.                         $glowny_licznik = $glowny_licznik + 1;
  320.                    
  321.                         $znak_mniejszosci=rindex($token_oracle,'<');
  322.                         $podkreslenie=rindex($token_oracle,'_');
  323.                         $SID_Bazy=substr($token_oracle,$znak_mniejszosci+1,$podkreslenie-$znak_mniejszosci-1);
  324.    
  325.                         $dwukropek=index($token_oracle,':');
  326.                         $Host=substr($token_oracle,0,$dwukropek);
  327.  
  328.                         print "\n----Oracle8----\n";
  329.                         print "Session : ",@tokens[3],"\n";
  330.                         print "Time start : ",@tokens[7],"\n";
  331.                         print "Duration : ",@tokens[9],"\n";
  332.                         print "Data GB : ",@tokens[10],"GB\n";
  333.                         print "SessionID : ",@tokens[16],"\n";
  334.                         print "SID Bazy : ",$SID_Bazy,"\n";
  335.                        
  336.                         #write to output file
  337.  
  338.                         print PLIK_WYNIKOWY @tokens[3],"    ";  #Session
  339.                         print PLIK_WYNIKOWY $Host,"     ";      #Host
  340.                         print PLIK_WYNIKOWY "Oracle","      ";  #Oracle
  341.                         print PLIK_WYNIKOWY $SID_Bazy,"     ";  #Database SID
  342.                         print PLIK_WYNIKOWY @tokens[7],"    ";  #Time start
  343.                         print PLIK_WYNIKOWY @tokens[9],"    ";  #Duration
  344.                         print PLIK_WYNIKOWY @tokens[10],"GB\n"; #Data GB
  345.                        
  346.                         if ( $boolean_only_xls )
  347.                         {
  348.                             $worksheet->write($glowny_licznik,0,@tokens[3]);
  349.                             $worksheet->write($glowny_licznik,1,$Host);
  350.                             $worksheet->write($glowny_licznik,2,"Oracle");
  351.                             $worksheet->write($glowny_licznik,3,$SID_Bazy);
  352.                             $worksheet->write($glowny_licznik,4,@tokens[7]);
  353.                             $worksheet->write($glowny_licznik,5,@tokens[9]);
  354.                             $worksheet->write($glowny_licznik,6,"@tokens[10] GB");
  355.                         }
  356.                        
  357.                         $boolean_check=0;
  358.                     }
  359.                
  360.                 }
  361.                 print "\n";
  362.                 last;
  363.             }
  364.         }
  365.         $boolean = 1;
  366. }
  367. close(CHECKBOOK);
  368. close(PLIK_WYNIKOWY);
  369. }
  370. else {
  371. print "File session_list.txt does not exist";
  372. }
  373.  
  374. if ( $boolean_only_xls eq 1 ) {
  375.     $workbook->close();
  376. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement