Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use Date::Calc;
- use Spreadsheet::WriteExcel;
- use Spreadsheet::WriteExcel::Utility;
- sub help_syntax {
- print "\nHelp Syntax :\n\n";
- print "Backuped FileSystems and Oracle (default) -> perl script_name.pl\n";
- print "Backuped FileSystems and Oracle in .xls format -> perl script_name.pl --xls\n";
- print "Backuped FileSystems -> perl script_name.pl --FS\n";
- print "Backuped FileSystems in format .xls -> perl script_name.pl --FS --xls\n";
- print "Backuped Oracle -> perl script_name.pl --Oracle\n";
- print "Backuped Oracle in format .xls -> perl script_name.pl --Oracle --xls\n\n";
- }
- $boolean_only_FS=0;
- $boolean_only_Oracle=0;
- $boolean_only_xls=0;
- if ( scalar(@ARGV) > 2 )
- {
- print "Numer of arguments is incorrect (max 2)\n";
- &help_syntax;
- exit;
- }
- my $workbook;
- my $worksheet;
- my ($x,$y)=(0,0);
- my $glowny_licznik=0;
- sub xls_function {
- $workbook = Spreadsheet::WriteExcel->new('output.xls');
- $worksheet = $workbook->add_worksheet('Backups');
- $format = $workbook->add_format();
- $format->set_bold();
- $format->set_align('center');
- $format->set_fg_color('grey');
- $format->set_size(12);
- $format->set_color('black');
- $worksheet->set_column(0,0,20);
- $worksheet->set_column(1,1,30);
- $worksheet->set_column(2,2,7);
- $worksheet->set_column(3,3,40);
- $worksheet->set_column(4,4,13);
- $worksheet->set_column(5,5,15);
- $worksheet->set_column(6,6,18);
- $worksheet->write(0,0,"Session",$format);
- $worksheet->write(0,1,"Server",$format);
- $worksheet->write(0,2,"Type",$format);
- $worksheet->write(0,3,"Backuped filesystems",$format);
- $worksheet->write(0,4,"Time start",$format);
- $worksheet->write(0,5,"Duration",$format);
- $worksheet->write(0,6,"Data GB",$format);
- }
- @lista_argumentow;
- foreach (@ARGV) {
- push(@lista_argumentow,$_);
- }
- if ( @lista_argumentow[0] eq "--help" || @lista_argumentow[0] eq "-help" || @lista_argumentow[0] eq "/h" || @lista_argumentow[0] eq "help" )
- {
- &help_syntax;
- exit;
- }
- elsif ( @lista_argumentow[0] eq "--xls" and @lista_argumentow[1] eq "" )
- {
- $boolean_only_xls=1;
- $boolean_only_FS=1;
- $boolean_only_Oracle=1;
- &xls_function;
- }
- elsif ( @lista_argumentow[0] eq "--FS" and @lista_argumentow[1] eq "--xls" )
- {
- $boolean_only_xls=1;
- $boolean_only_FS=1;
- &xls_function;
- }
- elsif ( @lista_argumentow[0] eq "--Oracle" and @lista_argumentow[1] eq "--xls" )
- {
- $boolean_only_xls=1;
- $boolean_only_Oracle=1;
- &xls_function;
- }
- elsif ( @lista_argumentow[0] eq "--FS" and @lista_argumentow[1] eq "" )
- {
- $boolean_only_FS=1;
- }
- elsif ( @lista_argumentow[0] eq "--Oracle" and @lista_argumentow[1] eq "" )
- {
- $boolean_only_Oracle=1;
- }
- elsif ( scalar(@ARGV) eq 0 )
- {
- $boolean_only_Oracle=1;
- $boolean_only_FS=1;
- }
- else
- {
- &help_syntax;
- exit;
- }
- ###################################################################################
- $omniback_path="D:/HP/OmniBack/bin";
- chdir($omniback_path) or die "Cannot open path $omniback_path\n";
- if (-e "omnirpt.exe" ) {
- print "Found omnirpt.exe\n";
- }
- else {
- print "File omnirpt.exe does not exist. Exit program.\n";
- exit;
- }
- $lista_sesji_command=`omnirpt.exe -report list_sessions -timeframe 24 24`;
- open FILE, ">session_list.txt" or die $!; #print list of session for Oracle and FileSystem
- print FILE $lista_sesji_command;
- close FILE;
- print "Created session list in file session_list.txt\n";
- if (-e "session_list.txt")
- {
- open (CHECKBOOK, "<session_list.txt");
- open (PLIK_WYNIKOWY, '>output.txt');
- $count = 0;
- $count_oracle=0;
- while ($record = <CHECKBOOK>) {
- @tokens = split(/\s+/, $record);
- my $boolean = 0;
- $count_oracle=0;
- $count=$count+1;
- foreach my $token (@tokens) {
- if ( @tokens[2] ne "Oracle8" and $boolean_only_FS eq 1)
- {
- if ( $boolean eq 0 )
- {
- if( @tokens[15] ne "Errors" )
- {
- if( @tokens[15] ne "" )
- {
- print "\n----FileSystem----\n";
- print "Session : ",@tokens[2],"\n";
- print "Time start : ",@tokens[6],"\n";
- print "Duration : ",@tokens[8],"\n";
- print "Data GB : ",@tokens[9],"GB\n";
- print "SessionID : ",@tokens[15],"\n";
- $temp_session_ID=@tokens[15];
- $session_objects=`omnirpt.exe -report session_objects -session $temp_session_ID`;
- $licz=0;
- $temp_host;
- $temp_host2;
- $boolean_session=1;
- $flaga_rowne=1;
- $flaga_nierowne=1;
- @tokens_session_objects = split(/\s+/, $session_objects);
- foreach my $token_session (@tokens_session_objects) {
- $licz=$licz+1;
- $temp_host=@tokens_session_objects[$licz];
- if( $token_session =~ m/FileSystem/)
- {
- $glowny_licznik = $glowny_licznik + 1;
- if ( $boolean_session )
- {
- $temp_host2=$temp_host;
- }
- ####################################################################################
- if ( $boolean_session )
- {
- print PLIK_WYNIKOWY @tokens[2]," "; #Session (once)
- if ( $boolean_only_xls )
- {
- $worksheet->write($glowny_licznik,0,@tokens[2]);
- }
- }
- if ( $boolean_session )
- {
- print PLIK_WYNIKOWY " ",@tokens_session_objects[$licz]," "; #host
- if ( $boolean_only_xls )
- {
- $worksheet->write($glowny_licznik,1,@tokens_session_objects[$licz]);
- }
- }
- else
- {
- print PLIK_WYNIKOWY " ",@tokens_session_objects[$licz]," "; #host
- if ( $boolean_only_xls )
- {
- $worksheet->write($glowny_licznik,1,@tokens_session_objects[$licz]);
- }
- }
- if ( @tokens_session_objects[$licz] eq $temp_host2 and $flaga_rowne == 1) #hosts name are the same
- {
- if ( $boolean_session )
- {
- print PLIK_WYNIKOWY "FS"," ";
- if ( $boolean_only_xls )
- {
- $worksheet->write($glowny_licznik,2,"FS");
- }
- }
- }
- if ( @tokens_session_objects[$licz] ne $temp_host2 and $flaga_nierowne == 1) #different host names
- {
- if ( $boolean_session )
- {
- print PLIK_WYNIKOWY "FS"," ";
- if ( $boolean_only_xls )
- {
- $worksheet->write($glowny_licznik,2,"FS");
- }
- }
- }
- if ( $boolean_session )
- {
- print PLIK_WYNIKOWY @tokens_session_objects[$licz+1]," "; #Backuped filesystems
- if ( $boolean_only_xls )
- {
- $worksheet->write($glowny_licznik,3,@tokens_session_objects[$licz+1]);
- }
- }
- else
- {
- print PLIK_WYNIKOWY @tokens_session_objects[$licz+1],"\n"; #Backuped filesystems
- if ( $boolean_only_xls )
- {
- $worksheet->write($glowny_licznik,3,@tokens_session_objects[$licz+1]);
- }
- }
- if ( @tokens_session_objects[$licz] eq $temp_host2 and $flaga_rowne == 1) #host names are the same
- {
- if ( $boolean_session )
- {
- print PLIK_WYNIKOWY @tokens[6]," "; #Time start (once)
- print PLIK_WYNIKOWY @tokens[8]," "; #Duration (once)
- print PLIK_WYNIKOWY @tokens[9],"GB\n"; #Data GB (once)
- $boolean_session=0;
- if ( $boolean_only_xls )
- {
- $worksheet->write($glowny_licznik,4,@tokens[6]);
- $worksheet->write($glowny_licznik,5,@tokens[8]);
- $worksheet->write($glowny_licznik,6,"@tokens[9] GB");
- }
- }
- $flaga_rowne=0;
- $flaga_nierowne=1;
- }
- if ( @tokens_session_objects[$licz] ne $temp_host2 and $flaga_nierowne == 1) #different host names
- {
- if ( $boolean_session )
- {
- print PLIK_WYNIKOWY @tokens[6]," "; #Time start (once)
- print PLIK_WYNIKOWY @tokens[8]," "; #Duration (once)
- print PLIK_WYNIKOWY @tokens[9],"GB\n"; #Data GB (once)
- $boolean_session=0;
- if ( $boolean_only_xls )
- {
- $worksheet->write($glowny_licznik,4,@tokens[6]);
- $worksheet->write($glowny_licznik,5,@tokens[8]);
- $worksheet->write($glowny_licznik,6,"@tokens[9] GB");
- }
- }
- $flaga_nierowne=0;
- $flaga_rowne=1;
- }
- $temp_host=@tokens_session_objects[$licz];
- $temp_host2=@tokens_session_objects[$licz];
- }
- }
- print "\n";
- $boolean = 1;
- }
- }
- }
- }
- elsif ( $boolean_only_Oracle eq 1 ) #in the session found Oracle8
- {
- $temp_session_oracle=@tokens[16]; #sessionID
- $oracle=`omnidb.exe -session $temp_session_oracle`;
- @tokens_oracle8 = split(/\s+/, $oracle);
- my $boolean_check=1;
- foreach my $token_oracle (@tokens_oracle8) {
- if( $token_oracle =~ m/.dbf/ and $boolean_check eq 1) #one host - one SID
- {
- $glowny_licznik = $glowny_licznik + 1;
- $znak_mniejszosci=rindex($token_oracle,'<');
- $podkreslenie=rindex($token_oracle,'_');
- $SID_Bazy=substr($token_oracle,$znak_mniejszosci+1,$podkreslenie-$znak_mniejszosci-1);
- $dwukropek=index($token_oracle,':');
- $Host=substr($token_oracle,0,$dwukropek);
- print "\n----Oracle8----\n";
- print "Session : ",@tokens[3],"\n";
- print "Time start : ",@tokens[7],"\n";
- print "Duration : ",@tokens[9],"\n";
- print "Data GB : ",@tokens[10],"GB\n";
- print "SessionID : ",@tokens[16],"\n";
- print "SID Bazy : ",$SID_Bazy,"\n";
- #write to output file
- print PLIK_WYNIKOWY @tokens[3]," "; #Session
- print PLIK_WYNIKOWY $Host," "; #Host
- print PLIK_WYNIKOWY "Oracle"," "; #Oracle
- print PLIK_WYNIKOWY $SID_Bazy," "; #Database SID
- print PLIK_WYNIKOWY @tokens[7]," "; #Time start
- print PLIK_WYNIKOWY @tokens[9]," "; #Duration
- print PLIK_WYNIKOWY @tokens[10],"GB\n"; #Data GB
- if ( $boolean_only_xls )
- {
- $worksheet->write($glowny_licznik,0,@tokens[3]);
- $worksheet->write($glowny_licznik,1,$Host);
- $worksheet->write($glowny_licznik,2,"Oracle");
- $worksheet->write($glowny_licznik,3,$SID_Bazy);
- $worksheet->write($glowny_licznik,4,@tokens[7]);
- $worksheet->write($glowny_licznik,5,@tokens[9]);
- $worksheet->write($glowny_licznik,6,"@tokens[10] GB");
- }
- $boolean_check=0;
- }
- }
- print "\n";
- last;
- }
- }
- $boolean = 1;
- }
- close(CHECKBOOK);
- close(PLIK_WYNIKOWY);
- }
- else {
- print "File session_list.txt does not exist";
- }
- if ( $boolean_only_xls eq 1 ) {
- $workbook->close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement