Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PERL Script on Windows Question

Posted on 2009-06-30
2
Medium Priority
?
810 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 1000 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

The main intent of this article is to make you aware of ‘Exchange fail to mount’ error, its effects, causes, and solution.
Steps to fix “Unable to mount database. (hr=0x80004005, ec=1108)”.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

783 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