This forum is currently locked. You can't register or post questions at this time. (read more)

Monitor the RAC services by using the UNIX shell scripts.

Questions relating to Oracle Real Application Clusters (RAC) and Clusterware.

Moderator: Tim...

shoan
Senior Member
Posts: 123
Joined: Thu Mar 17, 2011 6:27 am

Monitor the RAC services by using the UNIX shell scripts.

Postby shoan » Wed Feb 22, 2012 6:52 am

Hi Team,

Would you please anyone help me for the monitor the rac services by using the shell scripts for the following scenario ?

I have tow node RAC cluster setup.Each node having 3 instances. I have configured the preferred and avail services for the instances.

I want to create a unix shell script for sending a mail, Whenever the services are NOT RUNNING IN actual node or REALLOCATE ,FAIL-OVER to other instances.


Thanks in Advance

Shoan

Tim...
Site Admin
Posts: 18437
Joined: Mon Nov 01, 2004 5:56 pm
Location: England, UK
Contact:

Re: Monitor the RAC services by using the UNIX shell scripts

Postby Tim... » Wed Feb 22, 2012 11:19 am

Hi.

I created this service.

Code: Select all

$srvctl add service -d RAC -s OLTP_SERVICE -r RAC1 -a RAC2

$srvctl start service -d RAC -s OLTP_SERVICE


I then created a file called "test_service.sh" with the following contents.

Code: Select all

#!/bin/bash
# test_service.sh

function send_notification() {
  SERVICE_NAME=$1
  PREF_NODE=$2
  RUNNING_NODE=$3
  mail -s "Service not running on preferred node." "example@example.com" << END_MAIL
The $SERVICE_NAME service is running on $RUNNING_NODE, rather than $PREF_NODE.
END_MAIL
}

function check_service () {
  SERVICE_NAME=$1;
 
  PREF_NODE=`srvctl config service -d RAC -s $SERVICE_NAME | grep "Preferred instances:" | awk '{ print $3 }'`

  RUNNING_NODE=`srvctl status service -d RAC -s $SERVICE_NAME | awk '{ print $7 }'`
  echo "SERVICE_NAME="$SERVICE_NAME" PREF_NODE="$PREF_NODE" RUNNING_NODE="$RUNNING_NODE

  if [ "$PREF_NODE" != "$RUNNING_NODE" ]
  then
    echo "Send Notification."
    send_notification $SERVICE_NAME $PREF_NODE $RUNNING_NODE
  else
    echo "Service running as expected."
  fi
}

check_service $1


Made the script executable.

Code: Select all

$ chmod u+x test_service.sh


Now run it passing a service name.

Code: Select all

$ ./test_service.sh OLTP_SERVICE
SERVICE_NAME=OLTP_SERVICE PREF_NODE=RAC1 RUNNING_NODE=RAC1
Service running as expected.
$


I move the service onto the other node.

Code: Select all

$ srvctl relocate service -d RAC -s OLTP_SERVICE -i RAC1 -t RAC2


Call the script again.

Code: Select all

$ ./test_service.sh OLTP_SERVICE
SERVICE_NAME=OLTP_SERVICE PREF_NODE=RAC1 RUNNING_NODE=RAC2
Send Notification.
$


That would be my 5 minute stab at it. :)

Cheers

Tim...
Tim...
Oracle ACE Director
Oracle ACE of the Year 2006 - Oracle Magazine Editors Choice Awards
OakTable Member
OCP DBA 7.3, 8, 8i, 9i, 10g, 11g
OCP Advanced PL/SQL Developer
Oracle Database: SQL Certified Expert
My website: http://www.oracle-base.com
My blog: http://www.oracle-base.com/blog

shoan
Senior Member
Posts: 123
Joined: Thu Mar 17, 2011 6:27 am

Re: Monitor the RAC services by using the UNIX shell scripts

Postby shoan » Mon Feb 27, 2012 6:37 am

Hi Tim,

Great !!Thanks a lot !!

But my object is i have two node rac setup.Three databases are running on each node.

Each databases having 5 services are configured.
I need to check for all the services for each databases without passing the service name and database name manually.

I have little bit idea about the scripting .

Would you please help me for the above scenario ?

Thanks in Advance
Shoan

Tim...
Site Admin
Posts: 18437
Joined: Mon Nov 01, 2004 5:56 pm
Location: England, UK
Contact:

Re: Monitor the RAC services by using the UNIX shell scripts

Postby Tim... » Mon Feb 27, 2012 9:10 am

Hi.

Call the script once for each service. It's no hassle and you have to do all that work anyway.

Cheers

Tim...
Tim...
Oracle ACE Director
Oracle ACE of the Year 2006 - Oracle Magazine Editors Choice Awards
OakTable Member
OCP DBA 7.3, 8, 8i, 9i, 10g, 11g
OCP Advanced PL/SQL Developer
Oracle Database: SQL Certified Expert
My website: http://www.oracle-base.com
My blog: http://www.oracle-base.com/blog

shoan
Senior Member
Posts: 123
Joined: Thu Mar 17, 2011 6:27 am

Re: Monitor the RAC services by using the UNIX shell scripts

Postby shoan » Tue Mar 13, 2012 10:41 am

Hi Team,

I have put the services in a loop and it is working fine.

But i have small problem in my scripts.

Code: Select all

srvctl config service -d RAC
TEST_TAF  PREF: RAC1 RAC2   AVAIL: RAC3


If i am using the below scripting command the o/p is coming proper as per the above configuration .

Code: Select all

PREF_NODE=`srvctl config service -d RAC -s TEST_TAF  | grep "PREF:" | awk '{ print $3","$4  }'`


But i want to use the generic command so that it should give the output in between "PREF:" and "AVAIL:" in place of -> { print $3","$4 }.

For example:-

If the service configuration :-

TEST_TAF PREF: RAC1 RAC2 RAC3 AVAIL: RAC4

Output will be :-RAC1,RAC2,RAC3

Thanks in Advance
Shoan

Tim...
Site Admin
Posts: 18437
Joined: Mon Nov 01, 2004 5:56 pm
Location: England, UK
Contact:

Re: Monitor the RAC services by using the UNIX shell scripts

Postby Tim... » Tue Mar 13, 2012 11:13 am

Hi.

You've changed the rules now. When you started the post you said it was for use with 2-node RAC. You are now discussing situations with 3+ RAC nodes and lists of preferred nodes, rather than a single preferred node.

I don't have anything bigger than a 2 node RAc to test against, so I can't help.

Cheers

Tim...
Tim...
Oracle ACE Director
Oracle ACE of the Year 2006 - Oracle Magazine Editors Choice Awards
OakTable Member
OCP DBA 7.3, 8, 8i, 9i, 10g, 11g
OCP Advanced PL/SQL Developer
Oracle Database: SQL Certified Expert
My website: http://www.oracle-base.com
My blog: http://www.oracle-base.com/blog


Return to “Oracle RAC and Clusterware”

Who is online

Users browsing this forum: No registered users and 3 guests

cron