Verify reboot and oracle process with Perl Script
Here is a script I wrote that I will run in cron on the days that we have autosys reboot schedules. The script will check if the server has been rebooted in the last 2 hours and if it’s rebooted in the last 24 hours. It also checks to see if Oracle processes are running. In the case that either the reboot failed or the Oracle processes did restart or aren’t running it will send an e-mail notification to whoever is specified in the @to array variable.
#!/usr/bin/perl -w
#Written by: trizsolo
#Usage: ./autosysCheck.pl
#
our @ora_ps_list=@ARGV;
if(@ora_ps_list==0){
@ora_ps_list=('pmon', 'CRS', 'psp');
}
my $host=`hostname`;
chomp($host);
my $date=`date`;
chomp($date);
my $logfile='/tmp/' . $host . '.txt';
my $mailfile='/tmp/' . $host . 'mail.txt';
my $cmd=`cp $logfile $mailfile`;
open(LOG, ">$logfile") or die "Can't open $logfile: $!";
## Check the uptime of machine to see if it's been rebooted
## in the last 24 hours or in the last 2 hours
my $uptime=`uptime`;
if($uptime =~ m/day/i){
print LOG "$host has not been rebooted on $date!\n";
system($cmd) or die "Can't complete copy cmd: $!";
}elsif($uptime =~ m/up\s+(\d+)/){
if($1<=2){
print LOG "$host has been rebooted $1 hours ago on $date!\n";
}else{
print LOG "$host has been rebooted in last 24 hours but not in the last 2 hour!\n";
system($cmd) or die "Can't complete cmd: $!";
}
}
close(LOG);
## Check if Oracle processes $ instance is running
foreach my $ora_ps(@ora_ps_list){
$event_count{$ora_ps} = 0;
}
open(PS, "/bin/ps auwx |") or die "Cannot open cmd PS: $!";
$/="\n";
while(){
foreach my $ora_ps(@ora_ps_list){
if($_ =~ (m/$ora_ps/i)){
$event_count{$ora_ps}++;
}
}
}
close(PS);
## Log result of process verification
open(LOG, ">>$logfile") or die "Can't open $logfile: $!";
foreach $ora_ps(@ora_ps_list){
if($event_count{$ora_ps} ==0) {
print LOG "$host: Process $ora_ps is NOT running on $date!\n";
system($cmd) or die "Can't complete cmd: $!";
}else{
print LOG "$host: Process $ora_ps occurred $event_count{$ora_ps} times on $date!\n";
}
}
close(LOG);
my $mailer='/usr/sbin/sendmail -t';
our @to=('user1@domain.com', 'user2@domain.com');
my $from='superuser@' . $host;
my $subject='Autosys reboot & Oracle info';
if(-e $mailfile){
open(MAIL, "|$mailer") or die "Can't complete mail cmd: $!";
## Mail Header
print MAIL "To: @to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";
## Mail Body
print MAIL "Logs show $host either did not reboot properly or Oracle is not running!\n
Please check on $host.\n $date \n\n
$logfile\n\n";
close(MAIL);
}
exit 0;
August 24, 2008 at 11:17 pm
6lI’ll thingk about it.6r I compleatly agree with last post. gxq
паркет 2n
October 29, 2008 at 9:29 pm
great stuff, can you provide some coding to check the NT services.
November 6, 2008 at 5:52 pm
Greetings kdiao, there is a lot of Perl modules you can add for NT services. I focus most of my time and energy on *nix. I would suggest doing a google search for already written NT Perl scripts. example
intitle:perl + “NT service check”