Forum Discussion

issmag's avatar
issmag
Level 5
10 years ago

Perl Script

hello,

please i need your help,

how can i get a status backup with perl script, for a specific clients that are in file list (for example in the path : /usr/netbackup/myscript/clientList.txt ??

i have this script, but it's gave me the result about all clients :(

 

#!/usr/bin/perl

use Time::Local 'timelocal_nocheck';

$SITE = "My_Customer";
$REPORT_PATH = "/Downloads/Script-CompaNY/Reports/" ;

($datesec, $datemin, $dateh, $datej, $datem, $datea, $datesj, $dateaj, $dateisdst) = localtime (time);
$datem=$datem + 1;
$datea = $datea + 1900 ;

$_= $datem;
$count = tr/0-9// ;
if ($count eq 1) {$datem = "0$datem";}

$_= $datej;
$count = tr/0-9// ;
if ($count eq 1) {$datej = "0$datej";}

$TMSTMP= "${datea}_${datem}_${datej}" ;
$TMSTITRE= "${datej}/${datem}/${datea} ${dateh}:${datemin}:${datesec}" ;
my ($sec, $min, $heure, $jour, $mois, $annee, undef, undef, undef) = localtime(time-3600*25);
$mois += 1 and $annee -= 100;
$jour = sprintf("%02d",$jour);
$mois = sprintf("%02d",$mois);
my $BPDBJOBSDATE = "$mois/$jour/$annee $heure:$min:$sec";
$LOGFILE = "NBULog_CUSTOMER_INF_GROUP_Jour_${TMSTMP}" ;
@bpdbjobs =  `/usr/openv/netbackup/bin/admincmd/bpdbjobs -gdm -t $BPDBJOBSDATE` ;

open (LOG,"> ${REPORT_PATH}${LOGFILE}") or die "Unable to open ${LOGFILE}\n";
select(LOG);


$Nbre_Jobs = 0;
$Jobs_OK = 0;
$Jobs_code_1 = 0;
$Jobs_code_58 = 0;
$Jobs_code_150 = 0;
$Jobs_Act = 0;
$Jobs_Error = 0;
$nbre_client = 0;
foreach $JOBS ( @bpdbjobs ) {
        chomp ($JOBS) ;
        @JOBS = split(/,/, $JOBS);
        if(defined($JOBS[6]) ){
                        if ( $JOBS[1] eq 0)  {
                                ($sec, $min, $hour, $day, $mon, $year, $wday, $yday, $isdst) = localtime $JOBS[8];
                                $_= $min;
                                $count = tr/0-9// ;
                                if ($count eq 1) {$min = "0$min";}
                                $Mon = $mon + 1 ;
                                $Year = $year + 1900 ;
                                $STARTDATE= "${day}/${Mon}/${Year} ${hour}:${min}";

                                ($sec, $min, $hour, $day, $mon, $year, $wday, $yday, $isdst) = localtime $JOBS[10];
                                $_= $min;
                                $count = tr/0-9// ;
                                if ($count eq 1) {$min = "0$min";}
                                $Mon = $mon + 1 ;
                                $Year = $year + 1900 ;
                                if ( $Year < 1971 ) {$ENDDATE = "N/A"; }
                                else {$ENDDATE= "${day}/${Mon}/${Year} ${hour}:${min}";}

                                if ($ENDDATE == "N/A") {@JOBS[3] = Active ;}
                                $Nbre_Jobs++;
                                if($JOBS[3] eq '0'){$Jobs_OK++; $volumeT=$volumeT+$JOBS[16]; }
                                elsif($JOBS[3] eq '1'){$Jobs_OK++ ;$Jobs_code_1++ ; $volumeT=$volumeT+$JOBS[16];}
                                elsif($JOBS[3] eq '58'){$Jobs_code_58++ ; $Jobs_Error++ }
                                elsif($JOBS[3] eq '150'){$Jobs_code_150++}
                                elsif($JOBS[3] eq 'Active'){$Jobs_Act++}
                                else{$Jobs_Error++}
                                $JOBS[6] = substr($JOBS[6], 0, 35);

                                $line = "$SITE;$JOBS[3];$JOBS[6];$JOBS[5];$STARTDATE;$ENDDATE;$JOBS[16];$JOBS[17];$JOBS[4]";
                                push(@REPORT,$line);
#                       }
                }
        }
}
$CLI_Connect = `/usr/openv/netbackup/bin/admincmd/bpplclients -allunique -l |  uniq | wc -l`;
$nbre_client = `/usr/openv/netbackup/bin/admincmd/bpdbjobs -gdm -t $BPDBJOBSDATE | awk -F, '{print $7}' | sort | uniq | sed 1d | wc -l`;
$volumeT = ( $volumeT /1024 /1024);
$volumeT = substr($volumeT,0,7);
$Pourc = (($Jobs_OK / $Nbre_Jobs)*100);
$Pourc = substr($Pourc,0,5);
$Pourc_KO = (($Jobs_Error / $Nbre_Jobs)*100);
$Pourc_KO = substr($Pourc_KO,0,4);
$Pourc_Code1 = (($Jobs_code_1 / $Nbre_Jobs)*100);
$Pourc_Code1 = substr($Pourc_Code1,0,3);
print "Rapport des Jobs NetBackup pour les 25 dernieres Heures\nDate d\'execution : $TMSTITRE \n";
print "==================================================================\n";
print " Client: My_Customer Dedie\n";
print "==================================================================\n";
print "\n";
print "Detail des codes erreurs : http://www.symantec.com/docs/tech58686\n";
print "\n";
print "------------------------------------------------------------------\n";
print "\n";
printf ("%-40s%15s","Date de depart  ",": $BPDBJOBSDATE");
print "\n";
printf ("%-40s%15s","Nombre TOTAL de clients connectes   ",": $CLI_Connect");
printf ("%-40s%15s","Nombre TOTAL de clients sauvegardes  ",": $nbre_client");
printf ("%-40s%15s","Volume TOTAL de donnees sauvegardees",": $volumeT Go");
print "\n";
print "------------------------------------------------------------------\n";
print "\n";
print "Nombre TOTAL de Jobs                     : $Nbre_Jobs\n";
print "Nombre de Jobs OK                        : $Jobs_OK\n";
print "Nombre de Jobs Incomplets (code 1)       : $Jobs_code_1\n";
print "Nombre de Jobs Code 58 (cannot connect)  : $Jobs_code_58\n";
print "Nombre de Jobs termine par admin         : $Jobs_code_150\n";
print "\n";
print "------------------------------------------------------------------\n";
print "\n";
print "Nombre de Jobs Actifs                    : $Jobs_Act\n";
print "\n";
print "------------------------------------------------------------------\n";
print "\n";
print "Nombre de Jobs en ERREUR         : $Jobs_Error\n\n";
print "------------------------------------------------------------------\n";
print "\n";
print "Pourcentage de reussite                  : $Pourc %\n";
print "Pourcentage en erreur                    : $Pourc_KO %\n";
print "Pourcentage Code 1                       : $Pourc_Code1 %\n";
print "\n";
print "-" x 135;
print "\n";
print "-" x 135;
print "\n";
printf("%-17s%-7s%-35s%-13s%-16s%-16s%-12s%-10s%-20s%-20s\n","Site","Status","Client","Type","Start","End","KBytes","Files","Policy");
print "-" x 135;
print"\n";


foreach $LINE ( @REPORT ) {
  @DATA = split(/;/,$LINE);
  printf("%-17s%-7s%-35s%-13s%-16s%-16s%-12s%-10s%-20s%-20s\n",$DATA[0],$DATA[1],$DATA[2],$DATA[3],$DATA[4],$DATA[5],$DATA[6],$DATA[7],$DATA[8]);
}

close(LOG) ;

 

 

thanks in advance !

  • hello Miackael,

    yes right, is that exactly what i need, but i don't know how to do it :(

  • bpdbjobs | find "system-name-here" 

     

    Why not just do it this way? 

  • because i need a summary of thoses clients, and i'm not good at scripting, so if someone can help me to modufy the script to get a result just for a specific clients in the list.

  • Where are you reading in the values found in /usr/netbackup/myscript/clientList.txt?

  • that wha i need,

    i need the program to read clietList.txt entries,  and give me the results just for the clients in this file.

  • so run your perl script daily, then filter for the clients you only want to see..

     

    perl.pl > output

    for i in (`cat /usr/netbackup/myscript/clientList.txt`); do cat output | grep -i "$i";done

  • This is a Perl question. While I am certain that many of us here are familiar with Perl this is not the appropriate forum for asking for that kind of help.

  • You need to open the /usr/netbackup/myscript/clientList.txt file for reading and put in a comparison of the client_name and relevant $JOBS position.

    My suggestion is break it into two things, get the clienList.txt read through a loop and get the status of one client. Then combine the loop and getting the status for the one client

  • hello Miackael,

    yes right, is that exactly what i need, but i don't know how to do it :(

  • @issmag,

    If you still need a solution here is one:

    Start your script with the clientList.txt as an argument (perl myscript.pl clientList.txt).

    In the variable section of your script put in this:

    use strict;
    use warnings;
    use Text::CSV; (Use this if you have input that is in a CSV format which the output of bpdbjobs is and if you want to output to CSV)

    my $infile = $ARGV[0];
    my $outfile = $ARGV[1]; (I added this in case you wanted to write the output to a file)

    my $in = undef;
    my $out = undef;
    my $encd = ":encoding(UTF-8)";
    my $csv = Text::CSV->new({ sep_char => ',' });
    my $state = 0;

    In your processing of the list use this:

    open ($in, "< $encd", $infile) or die "Input file is not found $! \n";
    open ($out, ">> $encd", $outfile) or die "Could not open output file $! \n";
    while (my $lines = <$in>) {
      chomp $lines;
      if ($csv->parse($lines)) {
       my @line = $csv->fields();
       $state = $line[2];
      } else {
          print "Line could not be parsed! \n";
       }
       if ($state == $job) {
       print $out "$lines \n";
     }
    }
    close $in;
    close $out;