Script to modify Veritas HA Cluster Resource Configuration
The following interactive Korn shell script can be used to make common changes to the configuration of Veritas HA Cluster resources. The script enables you to view the listing of available resources; view resource configuration; online and offline resources; modify several parameters in resource configuration. The script was written to allow Oracle DBAs to make limited changes to VHA cluster configuration for specific database resources to facilitate Oracle upgrade and testing.
Sudo needs to be configured to allow authenticated oracle user to run this script with root credentials.
#!/bin/ksh # igor@krazyworks.com # November 9. 2005 # This script allows to interactively modify database settings for # Veritas Cluster Server service groups. Install this script in # /var/adm/bin on the Veritas HA cluster nodes. # This script was tested only on Solaris 8. While it may work under # other versions of SunOS and other Unix operating systems, it is # recommented that you test the script thorughly before placing it # in production. # SUPPORTED SYSTEMS: #--------------------------------------------------------------- # OS Name OS Version Veritas CS Version Tested #--------------------------------------------------------------- # SunOS 5.8 3.5 Y #--------------------------------------------------------------- log() { LOG="/var/log/oracle_modify.log" TMP="/tmp/oracle_modify.tmp" LINELIM=1000 ; LINEBUF=50 ; (( LINEMAX = LINELIM + LINEBUF )) if [ ! -r "$LOG" ] then touch "$LOG" fi if [ -f "$LOG" ] && [ `wc -l "$LOG" | awk '{print $1}'` -gt $LINEMAX ] then cat "$LOG" | tail -$LINELIM > "$TMP" mv "$TMP" "$LOG" fi } message() { echo "`hostname` `date +'%Y-%m-%d %T'` $MSG" >> "$LOG" } configure() { HARES="/opt/VRTS/bin/hares" if [ ! -x "$HARES" ] then HARES=$(which hares) if [ ! -x "$HARES" ] then MSG=$(echo "Executable hares not found.") ; message fi fi HACONF="/opt/VRTSvcs/bin/haconf" if [ ! -x "$HACONF" ] then HACONF=$(which haconf) if [ ! -x "$HACONF" ] then MSG=$(echo "Executable haconf not found.") ; message fi fi HALOG="/opt/VRTS/bin/halog" if [ ! -x "$HALOG" ] then HALOG=$(which halog) if [ ! -x "$HALOG" ] then MSG=$(echo "Executable halog not found.") ; message fi fi } view_db_list() { clear $HARES -list | more echo "Hit enter to return to menu... \c" read MENU2 menu } view_db_conf() { clear echo "Enter database name: \c" read db $HARES -display $db | more echo "Hit enter to return to menu... \c" read MENU2 menu } change_db_conf() { clear echo "Enter database name: \c" read db if [ `$HARES -display $db > /dev/null 2>&1 ; echo $?` -eq 0 ] then clear echo " Select the variable to change " echo " --------------------------------- " echo "| 1. Home |" echo "| 2. Pfile |" echo "| 3. Owner |" echo "| 4. ResourceOwner |" echo "| 5. Exit |" echo " ---------------------------------" echo "Your selection: \c" read MENU3 case "$MENU3" in 1) ATTR="Home" change_db_attribute ;; 2) ATTR="Pfile" change_db_attribute ;; 3) ATTR="Owner" change_db_attribute ;; 4) ATTR="ResourceOwner" change_db_attribute ;; 5) menu ;; *) echo "Invalid selection!" sleep 2 menu ;; esac else echo "Resource $db not found!" sleep 2 menu fi } change_db_attribute() { clear OLD=$($HARES -display $db -attribute $ATTR | fgrep -v "#" | awk '{print $4}') echo "Current value: $OLD" echo "" echo "Please enter the new value of $ATTR: \c" read NEW clear echo "WARNING! You are about to change the value of $ATTR for database $db." echo "" echo "Old value of ${ATTR}: $OLD" echo "New value of ${ATTR}: $NEW" echo "" MENU4="n" echo "Do you wish to make this change? [y/n]: \c" read MENU4 case "$MENU4" in y|yes) $HACONF -makerw $HARES -modify $db $ATTR $NEW if [ $? -eq 0 ] ; then echo "Change completed." MSG=$(echo "Changed value $ATTR for database $db from $OLD to $NEW") ; message $HACONF -dump -makero sleep 2 menu else echo "Change failed. Check database status." MSG=$(echo "Change failed for value $ATTR for database $db from $OLD to $NEW") ; message $HACONF -dump -makero sleep 2 menu fi ;; n|no) echo "Change aborted." sleep 2 menu ;; *) echo "Invalid response!" sleep 2 menu ;; esac } view_log() { clear LINES=10 echo "Showing last $LINES lines of the script log:" echo "---------------------------------------------" cat "$LOG" | tail -$LINES | more echo "" echo "Hit enter to return to menu... \c" read MENU2 menu } view_veritas_log() { clear LINES=10 echo "Showing last $LINES lines of the Veritas log:" echo "---------------------------------------------" $HALOG -cache $LINES echo "" echo "Hit enter to return to menu... \c" read MENU2 menu } online_db() { clear echo "Enter database name: \c" read db if [ `$HARES -display $db > /dev/null 2>&1 ; echo $?` -eq 0 ] then if [ `$HARES -display $db -attribute State | grep -v "#" | grep -c ONLINE` -eq 0 ] then echo "Do you wish to Enable database $db? [y/n]: \c" read MENU5 case "$MENU5" in y|yes) SERVERS=$($HARES -display $db -attribute State | grep -v "#" | grep OFFLINE | awk '{print $3}') clear echo "Bring $db online on which server?" echo " --------------------------------- " i=1 for SERVER in $SERVERS do echo "| ${i}. $SERVER" (( i = i + 1 )) done echo "| 0. Exit" echo " ---------------------------------" echo "Your selection: \c" read MENU6 case "$MENU6" in 1|2|3|4|5|6|7|8|9) echo "This operation will take about 20 seconds." j=1 $HARES -display $db -attribute State | grep -v "#" | grep OFFLINE | awk '{print $3}' | while read LINE do if [ $MENU6 -eq $j ] then SYSTEM=$(echo "$LINE") fi (( j = j + 1 )) done $HACONF -makerw $HARES -modify $db Enabled 1 $HARES -online $db -sys $SYSTEM sleep 20 if [ $? -eq 0 ] ; then echo "Database enabled." MSG=$(echo "Changed status of database $db to ONLINE") ; message $HACONF -dump -makero sleep 2 menu else echo "Operation failed! Check database status." MSG=$(echo "Failed to change status of database $db to ONLINE") ; message $HACONF -dump -makero sleep 2 menu fi ;; 0) menu ;; *) echo "Invalid selection!" sleep 2 menu ;; esac ;; n|no) echo "Operation aborted." sleep 2 menu ;; *) echo "Invalid response!" sleep 2 menu ;; esac else echo "Database $db already ONLINE." sleep 2 menu fi else echo "Database $db does not exist." sleep 2 menu fi } offline_db() { clear echo "Enter database name: \c" read db if [ `$HARES -display $db > /dev/null 2>&1 ; echo $?` -eq 0 ] then if [ `$HARES -display $db -attribute State | grep -v "#" | grep -c ONLINE` -eq 1 ] then echo "Do you wish to Disable database $db? [y/n]: \c" read MENU5 case "$MENU5" in y|yes) echo "This operation will take about 20 seconds." SYSTEM=$($HARES -display $db -attribute State | grep -v "#" | grep ONLINE | tail -1 | awk '{print $3}') $HACONF -makerw $HARES -offline $db -sys $SYSTEM sleep 20 $HARES -modify $db Enabled 0 if [ $? -eq 0 ] ; then echo "Database disabled." MSG=$(echo "Changed status of database $db to OFFLINE") ; message $HACONF -dump -makero sleep 2 menu else echo "Operation failed! Check database status." MSG=$(echo "Failed to change status of database $db to OFFLINE") ; message $HACONF -dump -makero sleep 2 menu fi ;; n|no) echo "Operation aborted." sleep 2 menu ;; *) echo "Invalid response!" sleep 2 menu ;; esac else echo "Database $db already OFFLINE." sleep 2 menu fi else echo "Database $db does not exist." sleep 2 menu fi } menu() { clear echo " Select operation " echo " --------------------------------- " echo "| 1. View database listing |" echo "| 2. View database config. |" echo "| 3. Modify database config. |" echo "| 4. Bring database online |" echo "| 5. Take database offline |" echo "| 6. View script log |" echo "| 7. View Veritas log |" echo "| 8. Exit |" echo " ---------------------------------" echo "Your selection: \c" read MENU case "$MENU" in 1) view_db_list ;; 2) view_db_conf ;; 3) change_db_conf ;; 4) online_db ;; 5) offline_db ;; 6) view_log ;; 7) view_veritas_log ;; 8) exit 0 ;; *) echo "Invalid selection!" sleep 2 menu ;; esac } #---------------------------------------- # RUNTIME #---------------------------------------- log configure menu
Popularity: 3% [?]
Related posts:


