Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scanning latest permenant errors in error logs 1

Status
Not open for further replies.

polani

Instructor
Jun 4, 2003
159
0
0
CA
Guys!!

I am try to build up a shell script which scans for permenant hardware errors in AIX error log and mail to specific users about these errors!!

i have nearly succeded in doing so , but stuck up at one step...

See , i am using errpt -s command with current date/time of system ( and this date/time is off course is the system time at which the script is run by cron)....

problem is that how can i insert date value of 24 hours back ( from current system time ) with errpt -s .... as i want to scan for only those errors which arrive in last 24 hours only....


Does somebody help me for providing any way to scan for errors in last 24 hours only..

Thanks in advance

Polani

Here comes polani Once again!!!

P690 Certified Specailist
HACMP & AIX Certified Specailist
AIX & HACCMP Instructor
 
HI,
in ksh:

integer DAY=`date +%d`
DAY=$DAY-1
if (( $DAY >=10 )) ;then
errpt -s `date +%m$DAY%H%M%y`
else
errpt -s `date +%m0$DAY%H%M%y` #add zero if less then 10
fi


Long live king Moshiach !
 
I use a perl script which is run via the cron every week day at 9am to scan the error log for all errors since the previous run. It uses a file to hold the previous run date which is used as a start date for the 'errpt' command.

Code:
#!/usr/bin/perl
#*********************************************************************
#
#	Name:		PrintErrorLog.
#
#	Function:	Prints detailed entries from the error log from the
#			last run date & time, if present.
#
#	Usage:		PrintErrorLog [ -h | -v ]
#
#	Created by:	Gerry Baker (November 2004).
#
#	Released:
#		v1.0 - 17/11/2004.
#
#*********************************************************************

use warnings;
use strict;
use Getopt::Std;
sub verify_usage;
sub usage_error;
sub get_current_run_date;
sub get_previous_run_date;
sub print_error_log;
sub update_run_date;

#
#	Declare and initialise all global variables.
#
our $version = "1.0";
our $basename = $0;
$basename =~ s<.*/><>;					### program base name ###
$= = 60;						### no. of lines per printed page ### 
our $current_run_date = "";
our $previous_run_date = "";
our $errpt_date_file = "/var/adm/ras/errpt.date";
our $now = time;					### today's date and time ###

#
#	Main process.	
#
{
verify_usage();
get_current_run_date();
get_previous_run_date();
print_error_log();
update_run_date();
exit;
}

sub verify_usage() {
#*********************************************************************
#
#	Check program flags and arguments.
#
#*********************************************************************
#
#	Process program options.
#
	my %option = ();
	getopts ("hv", \%option) or usage_error;
	usage_error if $ARGV[0];
	usage_error if defined $option{h};
	die ("$basename: Version $version\n") if defined $option{v};

} ### End of sub.

sub usage_error() {
#*********************************************************************
#
#	Display usage error and exit.
#
#*********************************************************************
	die <<EOF;

Usage:
$basename [ -h | -v ]

Switches
========
-h		Displays this message and exits.
-v		Displays the program version and exits.

EOF
} ### End of sub.

sub get_current_run_date() {
#*********************************************************************
#
#	Retrieve the current date and time and format for use in the
#	'errpt' command.
#
#*********************************************************************
#
#	Declare and initialise all local variables.
#
	my @date_time = ();
	my $minutes = "";
	my $hours = "";
	my $day = "";
	my $month = "";
	my $year = "";

#
#	Convert today's date and time into its components.
#
	@date_time = localtime ($now);

#
#	Format today's date and time.
#
	$minutes = sprintf ("%02d", $date_time[1]);
	$hours = sprintf ("%02d", $date_time[2]);
	$day = sprintf ("%02d", $date_time[3]);
	$month = sprintf ("%02d", $date_time[4] + 1);
	$year = sprintf ("%02d", substr ($date_time[5] + 1900, 2, 2));

#
#	Concatenate date and time fields into the format required for the
#	'errpt' command.
#
	$current_run_date = $month . $day . $hours . $minutes . $year;

} ### End of sub.

sub get_previous_run_date() {
#*********************************************************************
#
#	Retrieve the previous run date and time for this program from the
#	errpt date file, if it exists.
#
#*********************************************************************
#
#	Set previous run date to undefined if the errpt date file does not
#	exist.
#
	if ( not -e $errpt_date_file ) {
		undef $previous_run_date;
	}

#
#	Set previous run date to undefined if the errpt date file is
#	empty.
#
	elsif ( -z $errpt_date_file ) {
		undef $previous_run_date;
	}
	else {

#
#	open errpt date file for input.
#
		open (ERRPT_DATE, "<", $errpt_date_file)
			or die ("$basename: cannot open infile '$errpt_date_file' - $!\n");

#
#	Get previous run date and time.
#
		$previous_run_date = <ERRPT_DATE>;
		chomp ($previous_run_date);

#
#	Verify previous run date and time.
#
		if ( length $previous_run_date != 10 ) {
			undef $previous_run_date;
			warn ("$basename: Warning - previous run date invalid!!!\n");
		}
		elsif ( $previous_run_date !~ /^\d+$/ ) {
			undef $previous_run_date;
			warn ("$basename: Warning - previous run date not numeric!!!\n");
		}

#
#	close errpt date file.
#
		close ERRPT_DATE
			or die ("$basename: error closing infile '$errpt_date_file' - $!\n");

	}

} ### End of sub.

sub print_error_log() {
#*********************************************************************
#
#	Print details from the error log up to and including the previous
#	run date, if present.
#
#*********************************************************************
#
#	Declare and initialise local variables.
#
	my @month = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
	my @date_time = ();
	my $run_time = "";
	my $run_date = "";
	my $errpt_command = "/usr/bin/errpt -a";
	my $lp_pipe_open = 0;				### Boolean Flag ###
	my $lp_command = "lp -s -dauprt02";

#
#	Declare output formats.
#
format STDOUT_TOP =
GMB_P650 ERROR LOG as at @<<<< on @<<<<<<<<<<                          @>>>>>>>
$run_time, $run_date, "Page $%"

.

format STDOUT =
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$_
.

#
#	Add the previous run date to the 'errpt' command, if present.
#
	if ( defined $previous_run_date ) {
		$errpt_command .= " -s " . $previous_run_date;
	}

#
#	open input pipe to 'errpt' command.
#
	open (ERRORLIST, "-|", $errpt_command)
		or die ("$basename: cannot open pipe to '$errpt_command' - $!\n");

#
#	Format the run date and time.
#
	@date_time = localtime ($now);
	$run_time = sprintf ("%02d", $date_time[2]) . ":";
	$run_time .= sprintf ("%02d", $date_time[1]);
	$run_date = sprintf ("%02d", $date_time[3]) . " ";
	$run_date .= $month[$date_time[4]] . " ";
	$run_date .= $date_time[5] + 1900;
	
#
#	Write out each line from the error log.
#
	while ( <ERRORLIST> ) {

#
#	open output pipe to 'lp' command, first time only.
#
		if ( not $lp_pipe_open ) {
			open (STDOUT, "|-", $lp_command)
				or die ("$basename: cannot open pipe to '$lp_command' - $!\n");
			$lp_pipe_open = 1;
		}

#
#	Write a line to standard ouput.
#
	 	write;

	} ### end of while loop ###

#
#	close pipe to 'errpt' command.
#
	close ERRORLIST
		or die ("$basename: error closing pipe to '$errpt_command' - $!\n");

#
#	close pipe to 'lp' command, if open.
#
	if ( $lp_pipe_open ) {
		close STDOUT
			or die ("$basename: error closing pipe to '$lp_command' - $!\n");
	}

} ### End of sub.

sub update_run_date() {
#*********************************************************************
#
#	Amend the run date on the errpt date file to today's run date.
#
#*********************************************************************
#
#	open errpt date file for output.
#
	open (ERRPT_DATE, ">", $errpt_date_file)
		or die ("$basename: cannot open outfile '$errpt_date_file' - $!\n");

#
#	Replace the error log run date.
#
	print (ERRPT_DATE "$current_run_date\n");
 
#
#	close errpt date file.
#
	close ERRPT_DATE
		or die ("$basename: error closing outfile '$errpt_date_file' - $!\n");

} ### End of sub.

### End of program.
 
Try:

errpt -a -s `env TZ=MET+24 date +'%m%d%H%M%y'`


&quot;If you always do what you've always done, you will always be where you've always been.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top