Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 813
  • Last Modified:

PERL Script on Windows Question

Hi Experts,

As the lazy WinAdmin I am, I thought I could take the report.pl script floating around the Net and run it on Windows using ActivePerl. Upon configuring Sendmail and filepaths for Windows, I was getting the report but with no data.

I have been able to pinpoint this issue to line 48: report_span($report_time, $actual_time, $offset);

If I comment the line out I get data.

My questions are:
* What does the report_span do?
* Is it critical for the script?
* Is there a Windows analog for this?

Thanks,
#!C:/Perl/bin/perl.exe
#
# bpreport.pl
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
# 2007 - Mike Golvach - eggi@comcast.net
#
 
$first_tmp = $$;
$offset = $ARGV[0];
 
if ( -f "C:\\Tmp\\tmp.$first_tmp" ) {
 unlink("C:\\Tmp\\tmp.$first_tmp")
}
if ( $#ARGV = 0 ) {
 print "Usage: $0 TimeInSecondsToReportBack";
 exit(1)
}
 
system("C:\\progra~1\\VERITAS\\NetBackup\\bin\\admincmd\\bpdbjobs.exe -all_columns >>C:\\Tmp\\tmp.$first_tmp");
 
open(FT, "<C:\\Tmp\\tmp.$first_tmp");
@all_jobs = <FT>;
close(FT);
  print $job[3];
$global_error_flag = 0;
$separator = "***************************************************";
foreach $job (@all_jobs) {
 @file_list="";
 @job = split(/,/, $job);
 chomp($job[14]);
 if ( $job[14] =~ /^$/ ) {
  $job[14] = "0";
 }
 $error_flag = 0;
 $report_time = $job[8];
 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($job[8]);
 $today = parse_date($sec,$min,$hour,$mday,$mon,$year,$wday);
 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($job[10]);
 $today_end = parse_date($sec,$min,$hour,$mday,$mon,$year,$wday);
 if ( $today_end =~ /12\/31\/69/ )       {
  $today_end = "JOB IN PROGRESS";
 }
 $today_span_pre = ( $job[9] / 60 );
 $today_span = sprintf("%.2f", $today_span_pre);
 $actual_time = time;
 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
 $right_now = parse_date($sec,$min,$hour,$mday,$mon,$year,$wday);
 report_span($report_time, $actual_time, $offset);
 next if $dont_report;
 if ( $job[3] > 1 ) {
  @error_condition = `C:\\progra~1\\VERITAS\\NetBackup\\bin\\admincmd\\bperror.exe -S $job[3]`;
  $error_condition = $error_condition[0];
  $job[3] = $error_condition;
  $error_flag = 1;
  $global_error_flag = 1;
 }
 
 next if ( $job[6] eq "DSG" && $job[14] == 0 && ! $error_flag );
 $file_list=32;
 $file_list_still_going = 1;
 $just_starting = 1;
 while ($file_list_still_going) {
  if ( $job[$file_list] =~ /(\/|\\|ALL)/ ) {
   if ( $just_starting ) {
    push(@file_list, "$job[$file_list] ");
    $file_list++;
    $just_starting = 0;
   } else {
    push(@file_list, "| $job[$file_list] ");
    $file_list++;
   }
  } else {
   $file_list_still_going = 0;
  }
 }
 if ( $error_flag ) {
  push(@job_errors, "$job[6] | $job[5] | $job[14] kb | $today_span | $today | $today_end\n${job[3]
}@{file_list}\n$separator\n");
 } else {
  push(@job_successes, "$job[6] | $job[5] | $job[14] kb | $today_span | $today | $today_end\n@file_list\n$separator\n");
 }
}
 
$|=1;
print $job;
print "Printing stuff\n";
open(MAIL, "|C:\\sendmail\\sendmail.exe -t");
select(MAIL);
print "Subject: NetBackup Status Report cfebck01 - $right_now\n";
print "From: email\@domain\n";
print "Reply-To: email\@domain\n";
print "To: email\@domain.net\n";
print "\n\n";
print "NetBackup Status Report\n";
print "-----------------------------------------------\n";
print "\n";
print "Jobs With Errors To Report!\n\n$separator\n";
print "Server | Policy | Kb | Min Elapsed | Start Date | Time |End Date | Time\n";
print "Error\n";
print "File List\n";
print "$separator\n\n";
@job_errors = sort @job_errors;
$job_error_count = @job_errors;
if ( $job_error_count ) {
        print "@job_errors\n";
}       else    {
        print "NO ERRORS TO REPORT!!!\n\n"
}
print "-----------------------------------------------\n";
print "\nJobs Completed Successfully!\n\n$separator\n\n";
print "Server | Policy | Kb | Min Elapsed | Start Date | Time |End Date | Time\n";
print "File List\n";
print "$separator\n\n";
print @job_successes = sort @job_successes;
print "@job_successes\n";
select(STDOUT);
close(MAIL);
 
sub parse_date {
 
 my ($sec,$min,$hour,$mday,$mon,$year,$wday) = @_;
 %months = qw(0 Jan 1 Feb 2 Mar 3 Apr 4 May 5 Jun 6 Jul 7 Aug 8 Sep 9 Oct 10 Nov 11 Dec);
 %weekdays = qw(0 Sun 1 Mon 2 Tue 3 Wed 4 Thu 5 Fri 6 Sat);
 if ( $sec < 10 ) {
  $sec = "0" . $sec;
 }
 if ( $min < 10 ) {
  $min = "0" . $min;
 }
 if ( $hour < 10 ) {
  $hour = "0" . $hour;
 }
 if ( $mday < 10 ) {
  $mday = "0" . $mday;
 }
 if ( $yday < 10 ) {
  $yday = "0" . $yday;
 }
 $mon = $mon + 1;
 if ( $mon < 10 ) {
  $mon = "0" . $mon;
 }
 $wday = $weekdays{$wday};
 $year = 1900 + $year;
 $year =~ s/^..(.*)$/$1/;
 $nice_date = "${mon}/${mday}/$year | ${hour}:${min}:$sec";
}
 
sub report_span {
 
 my ($report_time,$actual_time,$offset) = @_;
 $dont_report = 0;
 $more_than_offset_hours_old = $actual_time - $report_time;
 if ( $more_than_offset_hours_old > $offset ) {
  $dont_report = 1;
 }
}

Open in new window

0
jimmlegs
Asked:
jimmlegs
1 Solution
 
narayanan13Commented:
Problem with $offset variable, actually $offset will be the first argument you are passing to this script during execution.

i'm not sure about data's you are using but the condition should be

($report_time - $actual_time ) < $offset

try to print some debug statements and see what are all data's passing to report_span()
0
 
jimmlegsAuthor Commented:
You rock narayanan!! once the $offset was called first the output came through.
I will be asking another question regarding this script shortly. Please keep an eye out for it!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now