<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl -w
use strict;

my $VERSION="1.2.0";

=head INFORMATION
#####################################################################
Author                  : Sanjoga Sahu
Modification            : 28th, Apr, 2009 (V1.0.0) [Initial Version]
                          20th, Oct, 2009 (V1.1.0) [Additional Functionality Addition]
						  29th, Apr, 2010 (V1.2.0) [Modified For Job dependancy] 

About                   : This is a simple and effective Autosys Job report Generator tool.


How to set alias Help   : 
-------------------------
Add an alias in .profile/.bashrc file
alias ajr=/path/autosys_job_reporter_1.2.0.pl
OR
alias b=/path/autosys_job_reporter_1.2.0.pl


Usage                   :
-------------------------
autosys_job_reporter_1.2.0.pl : Provides Information of Job's Important Attributes along with the Status &amp; more...

Options :
autosys_job_reporter_1.2.0.pl &lt;job Name&gt;
autosys_job_reporter_1.2.0.pl &lt;Job Name&gt; [&lt;-adDhpqtu&gt;]

-h : Help.
-a : All Options.
-u : Upstream Dependency.
-d : Downstream Dependency.
-D : Upstream and Downstream Dependency (job_depends).
-p : Previous Runs.
-q : Jil of Job.
-t : Calculates the Run Time of All Previous Runs.

#####################################################################


Color	Foreground	Background 
black	30			40 
red		31			41 
green	32			42 
yellow	33			43 
blue	34			44 
magenta 35			45 
cyan	36			46 
white	37			47 

bash$ echo -e "\033[1m  This is bold text. \033[0m"
bash$ echo -e "\033[4m  This is underlined text. \033[0m"

=cut

$|=10;

my $id=`id`;

chomp $id;
my $wide_chk_lenth=30;
my $no_sec=0;
my $user;
my $box_log;
my $log_flg=0;
my $add_info=1;
my $log_name="autosys_job_reporter.errlog";
my %GLOBAL_VAR=();


	if($id=~ /(\=\d+?)\s*\((.+?)\)/)
	{
	$user=$2;
	}

	if(defined $user)
	{
		if(-e "/home/$user" &amp;&amp; -w "/home/$user")
		{
			unless(-d "/home/$user/log")
			{
			system("mkdir /home/$user/log");
			}
		$box_log="/home/$user/log/$log_name";
		$log_flg=1;
		}
		elsif(-e "/$user" &amp;&amp; -w "/$user")
		{
		$box_log="/$user/$log_name";
		$log_flg=1;
		}
	}
#print "$box_log\n";


my $job=&amp;trim($ARGV[0]);

$job=&amp;valid($job);

#print "JOB:--$job--\n";

my $num_arg=scalar(@ARGV);

#print "ARGV--$num_arg--\n";

my $opts;

	if($num_arg &gt; 1)
	{
	shift(@ARGV);
		foreach my $op (@ARGV)
		{
		&amp;valid_opts($op);
		}
	$opts=join("",@ARGV);
	$opts=~ s/\-//g;
	&amp;check_opts($opts);
	#print "MORE...$opts...\n";
	}

	unless(defined $opts)
	{
	$opts="n";
	}

#print "OPTS=$opts=\n";

&amp;job_check($job,$opts);

#____PROG_END____#

####################### SUBROUTINE : job_check() ####################
=head
1. Check the job whether exist or not.
2. Gathers required box job and desired job's infromated output and prints.
3. Prints Additional Information of the job.
=cut

sub job_check
{
my ($job, $opts)=@_;
my $rec;
$job=&amp;trim($job);
my $box_f=0;
$rec=`autorep -J $job -q -l0`;

$rec=&amp;trim($rec);

my $rec_orig=$rec;
$rec=~ s/\n/_##_/g;
$rec=$rec."_##_";

#print "$rec\n";

	if(defined $job &amp;&amp; $job ne "")
	{
	my $box;
		if($rec=~/Invalid\s+Job\s+Name/i)
		{
		print "$rec_orig\n";
		$job=&amp;valid("");
		}
		
		if($rec=~/insert_job\s*\:\s*(.+?)\s*job_type:\s*b\s*_\#\#\_/)
		{
		$box=$1;
		$box_f=1;
		#print "---IN 1\n";
		}
		if($rec=~/box_name\s*\:\s*(.+?)\s*\_\#\#\_/)
		{
		$box=$1;
		#print "---IN 2\n";
		}
		
		if(defined $box &amp;&amp; $box ne "")
		{
		print "\n\033[1m================================================================\033[0m\n";
		print "\033[44m\033[37m\033[1mBox Information : $box\033[0m\n";
		my $jr=`autorep -J $box`;
		my $w=&amp;jr_wide_check($jr);
			
			if($w==1)
			{
			$jr=`autorep -J $box -w`;
			}

		my @lines=split(/\n/,$jr);
			foreach my $li (@lines)
			{
				if($li=~ /\b$job\b/)
				{
				print "\033[45m\033[37m\033[1m$li\033[0m\n";
				}
				else
				{
				print "$li\n";
				}
			}
		print "\n";
			if($box_f==1)
			{
			print "\033[44m\033[37m\033[1mBox Jil : $job\033[0m\n";
			print "\n$rec_orig\n";
			print "\n\033[1m================================================================\033[0m\n";
			#print "\n================================================================\n";
			exit(0) if($opts eq 'n');
			}
		}
		else
		{
		print "\n\033[1m================================================================\033[0m\n";
		print "\033[44m\033[37m\033[1mNo Box Job Found for this Job.\033[0m\n";
		my $jr=`autorep -J $job`;
		my $w=&amp;jr_wide_check($jr);
			
			if($w==1 )
			{
			$jr=`autorep -J $job -w`;
			}
		#print "$jr";
		my @lines=split(/\n/,$jr);
			foreach my $li (@lines)
			{
				if($li=~ /\b$job\b/)
				{
				print "\033[45m\033[37m\033[1m$li\033[0m\n";
				}
				else
				{
				print "$li\n";
				}
			}
		}
		
#####################################################################
		if($box_f !=1)
		{
		my ($prof, $script, $out, $err, $watch, $desc, $cond, $machine,$owner);
		my $prof_f=0;
			if($rec=~/profile\s*\:\s*(.+?)\s*\_\#\#\_/)
			{
			$prof=$1;
			$prof=&amp;trim($prof);
				if(defined $prof &amp;&amp; $prof ne "")
				{
				$prof_f=1;
				}
			}
			
		print "\n================================================================\n";
		print "\033[44m\033[37m\033[1mJob Information : $job\033[0m\n";

################### Serching Important Attributes ###################
		
			if($rec=~ /description\s*\:\s*(.+?)\s*\_\#\#\_/)
			{
			$desc=$1;
			print "Description: $desc\n";
			}
			if($rec=~ /condition\s*\:\s*(.+?)\s*\_\#\#\_/)
			{
			$cond=$1;
			print "Condition: $cond\n";
			}
			if($rec=~ /machine\s*\:\s*(.+?)\s*\_\#\#\_/)
			{
			$machine=$1;
			print "[machine: $machine] ";
			}
			if($rec=~ /owner\s*\:\s*(.+?)\s*\_\#\#\_/)
			{
			$owner=$1;
			print "[owner: $owner] ";
			}
			print "\n";

			print "\n";

			if($rec=~ /command\s*\:\s*(.+?)\s*\_\#\#\_/)
			{
			$script=$1;
			}
			if($rec=~ /std_out_file\s*\:\s*(.+?)\s*\_\#\#\_/)
			{
			$out=$1;
			}
			if($rec=~ /std_err_file\s*\:\s*(.+?)\s*\_\#\#\_/)
			{
			$err=$1;
			}
			if($rec=~ /watch_file\s*\:\s*(.+?)\s*\_\#\#\_/)
			{
			$watch=$1;
			}

########################## Printing Attributes ######################
		&amp;print_attr($script, $prof_f,$prof,"ls-no","command");
		&amp;print_attr($out, $prof_f,$prof,"ls-yes","std_out_file");
		&amp;print_attr($err,$prof_f,$prof,"ls-yes","std_err_file");
		&amp;print_attr($watch, $prof_f,$prof,"ls-yes","watch_file");
		&amp;print_attr($prof, $prof_f,$prof,"ls-no","profile");

		print "\n\033[1m================================================================\033[0m\n";
		}
###################### Additional Information #######################
		
		my $flg_p=0;
		if($opts  ne "n")
		{
		my @all_opts=split(/|/,$opts);
		my $all=join(" ",@all_opts);
			if($all=~ /a/)
			{	
			&amp;jr_q($job) if($box_f !=1);
			&amp;jr_u($job);
			&amp;jr_d($job);
			&amp;jr_p($job,1);
			&amp;jr_t($job);
			$flg_p=1;
			}
			else
			{
				foreach my $op (@all_opts)
				{
					if($op eq "q" &amp;&amp; $box_f !=1)
					{
					&amp;jr_q($job);
					$flg_p=1;
					}
					if($op eq "u")
					{
					&amp;jr_u($job);
					$flg_p=1;
					}
					if($op eq "D")
					{
					&amp;jr_D($job);
					$flg_p=1;
					}
					if($op eq "d")
					{
					&amp;jr_d($job);
					$flg_p=1;
					}
					if($op eq "p")
					{
					&amp;jr_p($job,1);
					$flg_p=1;
					}
					if($op eq "t")
					{
					&amp;jr_t($job);
					$flg_p=1;
					}
					if($op eq "h")
					{
					print "\033[44m\033[37m\033[1mInformation About $0 : [-h]\033[0m\n"; 
					&amp;usage();
					$flg_p=1;
					}
				}
			}
		
		print "\n\033[1m================================================================\033[0m\n" if($flg_p==1);
		}
	}#job defined
}


###################### SUBROUTINE : trim ()##########################
#removes prefix and postfixed space/newline/tab from input string

sub trim
{
my ($str)=@_;
return undef unless(defined $str);
$str=~s/^\s+|\s+$//g;
return $str;
}

###################### SUBROUTINE : valid ###########################
#Checks the string not to be a NULL one.

sub valid
{
my ($job)=@_;

	if(!defined $job)
	{
	&amp;usage();
	exit(11);
	}
	elsif($job eq "")
	{
	&amp;usage();
	exit(13);
	}
	elsif($job eq "-h")
	{
	print "\033[44m\033[37m\033[1mInformation About $0 : [-h]\033[0m\n"; 
	&amp;usage;
	exit(0);
	}
	else
	{
	return $job;
	}
}

#####################################################################

sub usage
{
print "\nUsage:\n\n$0 : Provides Information of Job's Important Attributes along with the Status &amp; more...\n";
print "\nOptions :\n";
print "$0 &lt;job Name&gt;\n";
print "$0 &lt;Job Name&gt; [&lt;-adDhpqtu&gt;]\n\n"; 
print "-h : Help.\n-a : All Options.\n-u : Upstream Dependency.\n-d : Downstream Dependency.\n-D : Upstream and Downstream Dependency (job_depends).\n-p : Previous Runs.\n-q : Jil of Job.\n-t : Calculates the Run Time of All Previous Runs.\n\n";

}

####################### SUBROUTINE : valid_opts() ###################
#checks the prefix of options.

sub valid_opts
{
my ($str)=@_;

	unless($str=~ /^-/ &amp;&amp; $str ne "-")
	{
	print "Invalid Option :$str\n";
	&amp;usage();
	exit(1);
	}
}

####################### SUBROUTINE : check_opts() ###################
#validates the options provided

sub check_opts
{
my ($str)=@_;
my @all_opts=split(/|/,$str);
#print "ALL_OPTS===@all_opts===\n";

	foreach my $op (@all_opts)
	{
		unless($op=~ /a|h|p|q|t|u|d|D/)
		{
		print "Invalid Option :$op\n";
		&amp;usage();
		exit(1);
		}
	}
}

##################### SUBROUTINE : substitute_WIN() #################
#subtitutes Win NT charaters with Unix charaters.
#This a tailor made subroutine can be changed as per the requirment.

sub substitute_WIN
{
my ($str)=@_;

$str=&amp;ini($str);

# ADD YOUR CODE HERE FOR HANDLING THE WIN&lt;&gt;UNIX PATH/ALIAS

$str=~ s|\\|/|ig;

return $str;
}


###################### SUBROUTINE : ini ()###########################
#initialize input string

sub ini
{
my ($str)=@_;
return "" unless(defined $str);
return $str;
}

################### SUBROUTINE : remove_env_str #####################
#removes unwanted lines/character from output after running the profile

sub remove_env_str
{
my ($str)=@_;

$str=&amp;ini($str);

my ($str_un,$str_nc)=split(/\//,$str,2);
$str_nc=&amp;ini($str_nc);

	if($str=~/\//)
	{
	$str_nc='/'.$str_nc;
	}
$str_nc=&amp;trim($str_nc);
	if($str_nc eq "")
	{
	$str_nc=$str;
	}
return $str_nc;
}

##################### SUBROUTINE : ls_file() ########################
# It lists the file. retuns not found message if the file can't be listed.

sub ls_file
{
my ($file)=@_;
my $ls_file;

	if(-f $file)
	{
	$ls_file=`ls -lrt \"$file\"`;
	chomp $ls_file;
	return $ls_file
	}
	else
	{
	return "$file [File Not Found]";
	}
}

################# SUBROUTINE : print_attr() #########################
# Prints  the result in a desired format.

sub print_attr
{
my ($attr, $flag, $prof,$ls_flg, $type)=@_;
$attr=&amp;trim($attr);
#print "=====$attr, ===$flag, ==$prof,=$ls_flg, -$type\n";

	if($flag==1)
	{
		if(defined $attr &amp;&amp; $attr ne "")
		{
		$attr=~ s/\bcp\b/CP/g;
		$attr=~ s/\bmv\b/MV/g;
		$attr=~ s/\brm\b/RM/g;
	
		$attr=~ s/\&gt;/\\&gt;/g;
		$attr=~ s/\&lt;/\\&lt;/g;
	
		$attr=~ s/\|/\\|/g;
		$attr=~ s/\&amp;/\\&amp;/g;
		$attr=~ s/\band\b/AND/g;
		$attr=~ s/\bor\b/OR/g;
		
		#Global Variable Fix
		my $var;
		$var=$1 if($attr=~ /\$\$(\S+)/);
		$var=$1 if($attr=~ /\$\$(\S+)(\.\S+)/);
		#print "====$var---\n";	
			if(defined $var)
			{
			my $gv=`autorep -G $var | grep $var`;
			$gv=&amp;trim($gv);
			$gv=$1	if($gv=~ /^\S+\s+(\S+)\s+/);
				if(defined $gv &amp;&amp; $gv ne "")
				{
					if($attr=~ /\$\$(\S+)(\.\S+)/)
					{
					$attr=~ s/(\$\$$1)/$gv/g;
					}
					elsif($attr=~ /\$\$(\S+)/)
					{		
					$attr=~ s/(\$\$\S+)/$gv/g;
					}
				}
			}
		my $val_scr;
		if($log_flg)
		{
		#print "------------\n";
		$val_scr=`__profile=$prof \n AUTO_JOB_NAME=$job \n . $prof 2&gt; $box_log \necho $attr`;
		#print "++++++++\n";
		}
		else
		{
		$val_scr=`__profile=$prof \n AUTO_JOB_NAME=$job \n . $prof \necho $attr`;
		}
		my $att_flg=0;
		if(defined $val_scr &amp;&amp; $val_scr ne "")
		{
		$val_scr=&amp;substitute_WIN($val_scr);
		$val_scr=&amp;remove_env_str($val_scr);
		}
		else
		{
		$val_scr=$attr;
		$ls_flg='ls-no';
		}

		$val_scr=~ s/\bCP\b/cp/g;
		$val_scr=~ s/\bMV\b/mv/g;
		$val_scr=~ s/\bRM\b/rm/g;
		$val_scr=~ s/\bAND\b/and/g;
		$val_scr=~ s/\bOR\b/or/g;
		
		$val_scr=~ s/\d{6}.out/*.out/g;
		$val_scr=~ s/\d{6}.err/*.err/g;

			if($ls_flg eq "ls-yes")
			{
			$val_scr=&amp;ls_file($val_scr);
			}
		print "$type\: $val_scr\n";
		}
	}
	else
	{
		if(defined $attr &amp;&amp; $attr ne "")
		{
		my $val_scr=&amp;substitute_WIN($attr);
			if($ls_flg eq "ls-yes")
			{
			$val_scr=&amp;ls_file($val_scr);
			}
		print "$type\: $val_scr\n";
		}
	}
return;
}


############### SUBROUTINE : jr_wide_check() ########################

=head
Checks if there is a requirment of printing (wide spaced job report).
sends a flag 1 if the job status string contains dots else 0
=cut

sub jr_wide_check
{
my ($str)=@_;

$str=~ s/\n/_#_#_/g;

	if($str=~ /\.\.\./)
	{
	return(1);
	}
	elsif(length $str &gt;= $wide_chk_lenth)
	{
	return(1);
	}
	else
	{
	return(0);
	}
}

######################### SUBROUTINE : jr_q() #######################
#shouws jil information of the job

sub jr_q
{
my ($job)=@_;
print "\n";
print "Please Wait...";
my $q=`autorep -J $job -q -l0`;
$q=&amp;trim($q);
print "\r\033[44m\033[37m\033[1mAdditional Information #$add_info : [-q] Jil of ($job)\033[0m\n\n";
$add_info++;
print "$q\n";
#print "\n\033[1m================================================================\033[0m\n";
return;
}

######################### SUBROUTINE : jr_u() #######################
#shows upstream dependency 
sub jr_u
{
my ($job)=@_;

print "\n";
print "Please Wait...";

my $res=`which job_depends`;

if($res !~ /^no\s+/)
{
my $depend=`job_depends -c -J $job`;

my $res;
my @dep=split(/\n/,$depend);
my %depend;
my %value;
my $depnd_flg=0;

	foreach my $dd (@dep)
	{
	$dd=&amp;trim($dd);
	next if($dd eq "");

		if($dd=~ /Atomic\s+Condition/i)
		{
		$depnd_flg=1;
		}
		if($dd=~ /Dependent\s+Job\s+Name/i)
		{
		$depnd_flg=0;
		}

		if($depnd_flg)
		{
			if($dd=~/^SUCCESS\(|^NOTRUNNING\(|^DONE\(|^s\(|^n\(|^d\(/i)
			{
			my @val=split(/\s+/i, $dd);
			my $job=$val[0];
			my $index=$#val;
			my $cond=$val[$index];
			$job=~ s/^SUCCESS\(|^NOTRUNNING\(|^DONE\(|^s\(|^n\(|^d\(//gi;
			$job=&amp;trim($job);
			$job=~ s/^\(|\)$//g;
			$depend{$job}=$cond;
			}
			elsif($dd=~/^VALUE\(|^v\(/)
			{
			my @val=split(/\s+/i, $dd);
			my $job=$val[0];
			my $index=$#val;
			my $cond=$val[$index];
			$job=~ s/^VALUE\(|^v\(//g;
			$job=&amp;trim($job);
			$job=~ s/^\(|\)$//g;
			$value{$job}=$cond;
			}
		}
	}

my $num=scalar(keys %depend);
my $glb=scalar(keys %value);
	if($num == 0 &amp;&amp; $glb ==0)
	{
	$res="No Upstream Dependency Found!\n";
	}
	else
	{
		foreach my $d (keys %depend)
		{
		my $jr=`autorep -J $d|grep "$d"`;
		$jr=&amp;trim($jr);
		my $cond;
		$cond="\033[30m\033[42m[ Dependecy Status: $depend{$d} ]\033[0m"	if($depend{$d}=~ /T/i);
		$cond="\033[30m\033[41m[ Dependecy Status: $depend{$d} ]\033[0m"	if($depend{$d}=~ /F/i);
		$res .=$jr."  $cond\n";
		}
		$res .="\nGlobal Name                  Value                        Last Changed\n-------------------------    -------------------------    --------------------\n" if(scalar keys %value &gt;0);
		
		foreach my $d (keys %value)
		{
		my $jr=`autorep -G $d|grep "$d"`;
		$jr=&amp;trim($jr);
		my $cond;
		$cond="\033[30m\033[42m[ Dependecy Status: $value{$d} ]\033[0m"	if($value{$d}=~ /T/i);
		$cond="\033[30m\033[41m[ Dependecy Status: $value{$d} ]\033[0m"	if($value{$d}=~ /F/i);
		$res .=$jr."  $cond\n";
		}
	}

print "\r\033[44m\033[37m\033[1mAdditional Information #$add_info : [-u] Upstream Dependency of ($job)\033[0m\n\n";
$add_info++;
print "$res";
#print "\n\033[1m================================================================\033[0m\n";
}
else
{
print "\r\033[44m\033[37m\033[1mAdditional Information #$add_info : [-u] Upstream Dependency of ($job)\033[0m\n\n";
$add_info++;
print "\r\033[41m\033[1mAutosys Command : \'job_depends\' Not Found!\033[0m\n";
}
#print "\n\033[1m================================================================\033[0m\n";
return;
}


######################### SUBROUTINE : jr_D() #######################
#Shows Downstream Dependency

sub jr_D
{
my ($job)=@_;
print "\n";
print "Please Wait...";

my $res=`which job_depends`;

if($res !~ /^no\s+/)
{
my $depend=`job_depends -c -J $job`;
$depend=&amp;trim($depend);

print "\r\033[44m\033[37m\033[1mAdditional Information #$add_info : [-D] Job Dependencies of ($job)\033[0m\n";
print "$depend\n";
}
return;
}

######################### SUBROUTINE : jr_d() #######################
#Shows Downstream Dependency

sub jr_d
{
my ($job)=@_;
print "\n";
print "Please Wait...";

my $res=`which job_depends`;

	if($res !~ /^no\s+/)
	{
	my $depend=`job_depends -c -J $job`;
	
	my $res;
	my @dep=split(/\n/,$depend);
	my @depend;
	my $depnd_flg=0;
		foreach my $dd (@dep)
		{
		$dd=&amp;trim($dd);
		#print "--$dd--\n";
			if($dd=~ /Dependent\s+Job\s+Name/i)
			{
			$depnd_flg=1;
			}
			if($depnd_flg)
			{
				if($dd=~/SUCCESS\(|NOTRUNNING\(|DONE\(|s\(|n\(|d\(|v\(|VALUE\(/i)
				{
				my ($val, $odd)=split(/SUCCESS\(|NOTRUNNING\(|DONE\(|s\(|n\(|d\(|v\(|VALUE\(/i, $dd, 2);
				$val=&amp;trim($val);
				$val=~ s/^\(|\)$//g;
				push(@depend,$val);
				}
			}
		}
	my $num=scalar(@depend);
		if($num == 0)
		{
		$res="No Downstream Dependency Found!\n";
		}
		else
		{
			foreach my $d (@depend)
			{
			my $jr=`autorep -J $d|grep "$d"`;
			chomp $jr;
			$res .=$jr."\n";
			}
		}

	print "\r\033[44m\033[37m\033[1mAdditional Information #$add_info : [-d] Downstream Dependency of ($job)\033[0m\n\n";
	$add_info++;
	print "$res";
	}
	else
	{
	print "\r\033[44m\033[37m\033[1mAdditional Information #$add_info : [-d] Downstream Dependency of ($job)\033[0m\n\n";
	$add_info++;
	print "\r\033[41m\033[1mAutosys Command : \'job_depends\' Not Found!\033[0m\n";
	}
#print "\n\033[1m================================================================\033[0m\n";
return;
}


######################### SUBROUTINE : jr_p() #######################
#shows previous job runs details
sub jr_p
{
my ($job, $flg)=@_;

print "\n" if($flg);
print "Please Wait..." if($flg);
my $res;

#autorep -j $job -l0 -r -2|grep $job
my $p="";
my $run=0;
	while( $p !~/Does\s+not\s+have\s+a\s+run/i)
	{
	$p=`autorep -j $job -l0 -r -$run|grep $job`;
		if($run==0 &amp;&amp; $p !~/Does\s+not\s+have\s+a\s+run/i)
		{
		$res="Latest Run   $run : $p";
		$run++;
		}
		else
		{
		$res .="Previous Run $run : $p";
		$run++;
		}
	}

print "\r\033[44m\033[37m\033[1mAdditional Information #$add_info : [-p] Previous Runs of ($job)\033[0m\n\n" if($flg);
$add_info++ if($flg);
print "$res" if($flg);
#print "\n\033[1m================================================================\033[0m\n";
return $res;
}

######################### SUBROUTINE : jr_t() #######################
#shows time taken for job to complete.

sub jr_t
{
my ($job)=@_;

print "\n";
print "Please Wait...";
my $res="";
my $t=&amp;jr_p($job,0);
my @all=split(/\n/,$t);
pop @all;

	foreach my $li (@all)
	{
		if($li =~ /\-\-/)
		{
		my ($prefix, $time_stamp)=split(/\:/,$li,2);
		my ($start, $end, $status);
			#yyyyyyyy     -----                02/24/2007  23:38:41 SU 0/0
			#xxxxxxxx     -----                08/01/2008 14:21 OI 57904994/1
			if($time_stamp =~ m|\s+\-\-\-\-\-\s+(\d{2}/\d{2}/\d{4}\s+\d{2}:\d{2}(:\d{2})?)\s+(\w{2})\s+|)
			{
			$end=&amp;trim($1);
			$status=$3;
			my $sec=$2;
			$end=~ s|(\d{2})/(\d{2})/(\d{4})|$3-$1-$2|g;
				if(defined $sec)
				{
				$start="####-##-## ##:##:##";
				}
				else
				{
				$start="####-##-## ##:##";
				$no_sec=1;
				}
			$res .="$prefix: $start  to  $end  $status ==&gt; N/A for Time Calc.\n";
			}

			#zzzzzzxxxxxxx     03/04/2009  20:15:11 -----                RU 4411130/1
			#ttttttttttttt     06/24/2009 22:50 -----            RU 68570413/1
			elsif($time_stamp =~ m|\s+(\d{2}/\d{2}/\d{4}\s+\d{2}:\d{2}(:\d{2})?)\s+\-\-\-\-\-\s+(\w{2})\s+|)
			{
			$start=&amp;trim($1);
			$status=$3;
			my $sec=$2;
			$start=~ s|(\d{2})/(\d{2})/(\d{4})|$3-$1-$2|g;
                                if(defined $sec)
                                {
                                $end="####-##-## ##:##:##";
                                }
                                else
                                {
                                $end="####-##-## ##:##";
                                $no_sec=1;
				}
			$res .="$prefix: $start  to  $end $status ==&gt; ";
			$end=`date "+%m/%d/%Y %H:%M:%S"`;
			chomp $end;
			$start=~ s|(\d{2})/(\d{2})/(\d{4})|$3-$1-$2|g;
			$end=~ s|(\d{2})/(\d{2})/(\d{4})|$3-$1-$2|g;

			my ($days,$hr,$min, $secs)=&amp;time_taken(date1 =&gt; $start,date2 =&gt; $end);
			
			$res .="$days Days, $hr Hr, $min Min, $secs Sec. (Time Elapsed Till Now)\n";
			}
			elsif($time_stamp =~ m|\s+\-\-\-\-\-\s+\-\-\-\-\-\s+(\w{2})\s+|)
			{
			$status=$1;
				if($no_sec)
				{
				#not satisfing now...
				$res .="$prefix: ####-##-## ##:##  to  ####-##-## ##:## $status ==&gt; N/A for Time Calc.\n";
				}
				else
				{
				#$res .="$prefix: ####-##-## ##:##:##  to  ####-##-## ##:##:## $status ==&gt; N/A for Time Calc.\n";
				$res .="$prefix: ####-##-## ##:##  to  ####-##-## ##:## $status ==&gt; N/A for Time Calc.\n";
				}	
			}
		}
		else
		{
		#print "----$li---\n";
		#$li : Latest Run   0 : 03/04/2009  05:21:38 03/04/2009  05:21:40 SU 4403364/1
		my ($prefix, $time_stamp)=split(/\:/,$li,2);
		#print "--$time_stamp---\n";
		#xxxxxxxxx       03/04/2009  05:21:38 03/04/2009  05:21:40 SU 4403364/1	
		#ddddddddd 06/24/2009 20:30 06/24/2009 20:32 SU 68570413/1	
			if($time_stamp=~ m|\s+(\d{2}/\d{2}/\d{4}\s+\d{2}:\d{2}(:\d{2})?)\s+(\d{2}/\d{2}/\d{4}\s+\d{2}:\d{2}(:\d{2})?)\s+(\w{2})\s+|)
			{
			my $start=&amp;trim($1);
			my $end=&amp;trim($3);
			my  $status=$5;
			$no_sec=1 unless(defined $2);
			
			$start=~ s|(\d{2})/(\d{2})/(\d{4})|$3-$1-$2|g;
			$end=~ s|(\d{2})/(\d{2})/(\d{4})|$3-$1-$2|g;
			my ($days,$hr,$min, $sec)=&amp;time_taken(date1 =&gt; $start,date2 =&gt; $end);
			$res .="$prefix: $start  to  $end $status ==&gt; $days Days, $hr Hr, $min Min, $sec Sec.\n"; 
				
			}
		}
	}

print "\r\033[44m\033[37m\033[1mAdditional Information #$add_info : [-t] Run Time for ($job)\033[0m\n\n";
$add_info++;
print "$res";
print "\nCurrent Time   : " ,`date`;
return;
}

##################### SUBROUTINE : time_taken() #####################

=head
Calculates the job run time.

input string :
key1 : Start date   =&gt; value1 : YYYY-MM-DD hh:mm:ss
key2 : End date     =&gt; value2 : YYYY-MM-DD hh:mm:ss

returns :
days, hours, min, and sec.

=cut

sub time_taken (%) {
	my %args = @_;
	my @offset_days = qw(0 31 59 90 120 151 181 212 243 273 304 334);

	my $year1  = substr($args{'date1'}, 0, 4);
	my $month1 = substr($args{'date1'}, 5, 2);
	my $day1   = substr($args{'date1'}, 8, 2);
	my $hh1    = substr($args{'date1'},11, 2) || 0;
	my $mm1    = substr($args{'date1'},14, 2) || 0;
	my $ss1    = substr($args{'date1'},17, 2) if (length($args{'date1'}) &gt; 16);
	   $ss1  = 0 unless (defined $ss1);
#print "$args{'date1'}\n";
#print "---$year1--$month1--$hh1--$mm1--$ss1--\n";

	my $year2  = substr($args{'date2'}, 0, 4);
	my $month2 = substr($args{'date2'}, 5, 2);
	my $day2   = substr($args{'date2'}, 8, 2);
	my $hh2    = substr($args{'date2'},11, 2) || 0;
	my $mm2    = substr($args{'date2'},14, 2) || 0;
	my $ss2    = substr($args{'date2'},17, 2) if (length($args{'date2'}) &gt; 16);
	   $ss2  = 0 unless (defined $ss2);

	my $total_days1 = $offset_days[$month1 - 1] + $day1 + 365 * $year1;
	my $total_days2 = $offset_days[$month2 - 1] + $day2 + 365 * $year2;
	my $days_diff   = $total_days2 - $total_days1;

	my $seconds1 = $total_days1 * 86400 + $hh1 * 3600 + $mm1 * 60 + $ss1;
	my $seconds2 = $total_days2 * 86400 + $hh2 * 3600 + $mm2 * 60 + $ss2;

	my $ssDiff = $seconds2 - $seconds1;

	my $dd     = int($ssDiff / 86400);
	my $hh     = int($ssDiff /  3600) - $dd *    24;
	my $mm     = int($ssDiff /    60) - $dd *  1440 - $hh *   60;
	my $ss     = int($ssDiff /     1) - $dd * 86400 - $hh * 3600 - $mm * 60;

return ($dd, $hh, $mm , $ss);
}


</pre></body></html>