Friday, August 19, 2011

Script/Automation: How to execute a script across all RAC nodes.

Often times, you may have run into scenarios where there is a need to run the same command across all the RAC nodes. I have attempted to automate this and the script is listed below.

Assumptions made for this script to work
1. The script you want to execute is accessible to all the nodes in a RAC environment either through NFS shared mount point or a common directory.
2. This script uses crs_stat to find all the nodes in a RAC. Ensure ORACLE_HOME and PATH variables are set appropriately.
3. Make sure secure shell login is permitted across all the nodes in the RAC cluster.




# Purpose: To execute a  unix script across all the nodes of a RAC environment
#
usage ()
{
     print "Usage ${PROGRAM_NAME} '<SCRIPT FILE with options>'";
     print "Eg.   ${PROGRAM_NAME}  '/nfsmount/script_name'";
     exit 3
}

PROGRAM_NAME=`basename $0`;
if (( $# < 1 ))
   then
     print "Required parameter not specified"
     usage;
fi
# Get the options supplied.
CMD=$1;
FILE=$(echo $1 | awk '{print $1}');
# Check if the file exists in the current server.

if [[ ! -f ${FILE} ]]
then
     print "Incorrect script file specified and/or the file is not accessible";
     usage;
fi;
crs_stat -t | awk '{ print $NF }' | grep -v 'Host' | grep -v '\-'  > /tmp/node_list;
for  listedhost in `sort /tmp/node_list | uniq`
do
   print "\nExecuting the Script on $listedhost ....\n\n";
   ssh -l oracle $listedhost ". /opt/oracle/.oravar; $CMD"
done;

No comments:

Post a Comment