Operating System - HP-UX
1832604 Members
2311 Online
110043 Solutions
New Discussion

automate monitoring script in hpux. promise of good points

 
SOLVED
Go to solution
apple
Super Advisor

automate monitoring script in hpux. promise of good points

i have one monitoring script inside in this path to check whether the oracle is running or not:
/disc01/script/monitor_oracle.sh

what is the best to put inside my crontab:

1. 15 * * * * * /disc01/script/monitor_oracle.sh >> /appl/oraclestatus.txt

2. 0 7 * * * /disc01/script/monitor_oracle.sh

but for option 2, where is the output will be directed to?

the script that we would like to run is more less like the attachment.

hope to hear from you. thanks a lot
10 REPLIES 10
Sajjad Sahir
Honored Contributor

Re: automate monitoring script in hpux. promise of good points


ps -eaf | grep ora
command in u shell script

Shrikant Lavhate
Esteemed Contributor
Solution

Re: automate monitoring script in hpux. promise of good points

Hi,

>but for option 2, where is the output will be directed to?

There is no way log of your script will be saved in some location as it is not mentioned in script or in command of crontab entry. Only way out is you can redirect output as in entry 1 or else redirect output under shell script only so there is no need of redirection in crontab entry.

-=ShRi=-
Will it remain a personal, if I broadcast it here!
Michael Steele_2
Honored Contributor

Re: automate monitoring script in hpux. promise of good points

Add a TIME variable to your script so you can track the launch.

TIME=$(date %.%.%) (* see man pages for % arguements *)
echo "Starting IQ" "\t" $TIME

####

2. 0 7 * * * /disc01/script/monitor_oracle.sh >> /dir/logfile.txt 2>&1

You want 2>&1 to capture output and errors and redirect them into the same file. So you should also add 2>&1 to the first entry.

1. 15 * * * * * /disc01/script/monitor_oracle.sh >> /appl/oraclestatus.txt 2>&1
Support Fatherhood - Stop Family Law
Rita C Workman
Honored Contributor

Re: automate monitoring script in hpux. promise of good points

Let's take a look at your cronfile..
Line 1 - You are running the script at 15 minutes after every hour of every day of every month....
Line 2 - You are running the SAME script at 7am everyday of every month....
>>>>>>> If that is what you want, then ok. But looks like you got alot of time between checking. And for the second line, why not just append it to the same file as line one. It's the same script.

Next let's look at your script:
Your grep entries are specific to your environment, but you seem to do a basic check to see if the oracle process is running. Now I've seen where the database went down, but oracle processes got left up and hung, so that doesn't really mean the the database is up and working properly.
And your hourly script only sends results to a file. Guess I might tend to send some kind of email alert if you don't have a good result & append to the logfile. You might consider adding this to your script. Cause when you monitor (even hourly) you want alerted as soon as it detects anything that might be a problem.

Just a couple thoughts,
Regards,
Rita
Bill Hassell
Honored Contributor

Re: automate monitoring script in hpux. promise of good points

Several things will improve your script:

> PS=`ps -eaf | grep asiqsrv12 | grep inside | grep -v grep | wc -l`

Never, ever use grep to find programs by name. grep has no concept of where the program's name is located and will anywhere on the command line. If the program's name is asiqsrv12 then tell ps to find the exact match(es) for you:

UNIX95=1 ps -C asiqsrv12

This eliminates the extra grep -v and also eliminates mistakes like finding asiqsrv123 or ABasiqsrv12 (which grep will do). ps knows the exact process name. There is no need to use extra options (-eaf) since all you want is a process count. Now if there are multiple copies of asiqsrv12 running and you need to refine the list by searching for inside (insides.cfg? maybe /SYB_02/db/insides.cfg) then using grep is OK. But use the largest pattern string to avoid mistakes. And also use grep to count for you:

PS=$(UNIX95=1 ps -C asiqsrv12 | grep -c asiqsrv12)

Note also that back ticks (reverse apostrophes or grave accent marks) are deprecated. Use $(...) instead (see the man page for sh-posix or ksh)

For cron (and at and batch), always use a redirect of the output in order to put the details into a logfile. And sometimes, error messages are sent to stderr so redirect both stdout and stderr to a file:

15 * * * * * /disc01/script/monitor_oracle.sh >> /appl/oraclestatus.txt 2>&1
0 7 * * * /disc01/script/monitor_oracle.sh >> /appl/oraclestatus.txt 2>&1

The construct: 2>&1 means: take stderr (2) and redirect it into file 1 (&1) which is stdout. As mentioned before, always use a timestamp so you can tell when the message occurred. Using YYYYMMDD.HHMM will allow exact searches:

echo "$(date +%Y%m%d.%H%M%S) IQ is running, not restarting"


Bill Hassell, sysadmin
Yogeeraj_1
Honored Contributor

Re: automate monitoring script in hpux. promise of good points

hi,

Would it be more wise to make the script push the status to a mailbox instead?

Also, as Rita mentioned, you have decide on a right frequency for the collection of the monitoring status.

revert.

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Dennis Handly
Acclaimed Contributor

Re: automate monitoring script in hpux. promise of good points

>Rita: Line 1 - You are running the script at 15 minutes after every hour

Alternately if you want to run it every 15 minutes, you should use:
0,15,30,45 * * * * * /disc01/script/monitor_oracle.sh
Yogeeraj_1
Honored Contributor

Re: automate monitoring script in hpux. promise of good points

hi Again,

below something you can try and see if it meets your requirements:

todo: Add a similar entry in your crontab

#*******************************************************************************
# min|hour |day |month|day |script
# | |of mo| |of wk|
#----|-----|-----|-----|-----|--------------------------------------------------
#*******************************************************************************
00,15,30,45 * * * * /disc01/script/monitor_oracle.sh | /bin/mailx -s "Oracle Monitor:: DB Status ($(date +\%H\%M)) " youremailaddress@mydomain.mu >/dev/null 2>&1
#*******************************************************************************
# END OF TABLE day0->Sunday day6->Saturday
#*******************************************************************************


hope this helps!

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Arturo Galbiati
Esteemed Contributor

Re: automate monitoring script in hpux. promise of good points

Hi,
take care that if your script will run when the backup of teh database or backup of the whole server you will log a ot of message about "database not running".
To avoid this in the script that will perform the backup touch a flag file 'backup-is-running' and in your monitor script check the existence of teh same.
Just my .02$
HTH,
Art
Yogeeraj_1
Honored Contributor

Re: automate monitoring script in hpux. promise of good points

hi again,

if you want to implement the steps as mentioned by Arturo above, then modify your script as follows:

#*******************************************************************************
# min|hour |day |month|day |script
# | |of mo| |of wk|
#----|-----|-----|-----|-----|--------------------------------------------------
#*******************************************************************************
00,15,30,45 * * * * [ ! -f /disc01/status/donotmonitor ] && /disc01/script/monitor_oracle.sh | /bin/mailx -s "Oracle Monitor:: DB Status ($(date +\%H:\%M)) " youremailaddress@mydomain.mu >/dev/null 2>&1
#*******************************************************************************
# END OF TABLE day0->Sunday day6->Saturday
#*******************************************************************************

Explanation:
When you dont want the script to run, just create an empty file (touch /disc01/status/donotmonitor)

hope this helps!

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)