Solved

PERL Script on Windows Question

Posted on 2009-06-30
2
788 Views
Last Modified: 2013-11-15
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
Comment
Question by:jimmlegs
2 Comments
 
LVL 1

Accepted Solution

by:
narayanan13 earned 250 total points
ID: 24747100
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
 
LVL 4

Author Closing Comment

by:jimmlegs
ID: 31598357
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

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
combine multiple lines 2 75
Software for IT quotations, invoices, delivery orders 2 63
CD-RW/DVD-ROM DRIVE 3 66
SonarQube on Linux vs Windows 3 82
Workplace bullying has increased with the use of email and social media. Retain evidence of this with email archiving to protect your employees.
All of the resources available today make learning a new digital media easier than ever-- if you know where to begin. This is a clear, simple guide to a few of the basic digital art mediums and how to begin learning them on your own.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…

697 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question