Svconfing
Svconfing
/bin/bash
# svc-show-config.sh - show nice tables with the databases services configuration, can also relocate
services to preferred instances (https://bit.ly/307P7F8)
# You should have received a copy of the GNU General Public License
# History :
# for the services to be offline (like the instance is down or the service is disabled)
TEMP=$(mktemp) # A tempfile
OLR="/etc/oracle/olr.loc" # olr.loc file to get crs home if oratab does not have ASM entry
# Usage function
usage() {
svc-show-config.sh - show nice tables with the databases services configuration, can also
relocate services to preferred instances (https://bit.ly/307P7F8)
END
printf "\n\033[1;37m%-8s\033[m\n" "SYNOPSIS" ;
$0 [-d] [-g] [-G] [-p] [-P] [-f] [-r] [-b] [-R] [-h]
END
$(basename $0):
Service name, Preferred instances, Available instances, Failback (Yes or No), Role (Primary,
Standby)
- Can also reolocate to the preferred instances (be aware that this is a force relocate by default, if
you want a non force service relocation, you should check the failback yes feature:
https://bit.ly/3bg9z8D)
END
-g | --grep ) a (no key sensitive) string to grep in the DB name and ORACLE_HOME
(optional)
-G | --ungrep ) a (no key sensitive) string to ungrep (grep -v) in the DB name and
ORACLE_HOME (optional)
-p | --showcode | --topref ) also shows the commands to run to restart the services on the
preferred instances (optional)
-P | --showcodeonly | --toprefonly ) only shows the commands to run to restart the services on
the preferred instances (optional)
-f | --force ) use -f option to stop service (kill the currently connected sessions)
(optional)
-R | --relocate ) Relocate the services (shortcut for --badonly --toprefonly --force --do)
END
END
exit 999
# Options
SHORT="g:,G:,d:,p,P,f,r,b,R,h"
LONG="grep:,ungrep:,db:,topref,toprefonly,force,do,badonly,relocate,showcode,showcodeonly,hel
p"
#
options=$(getopt -a --longoptions "${LONG}" --options "${SHORT}" -n "$0" -- "$@")
printf "\033[1;31m%s\033[m\n" "$($TS) [ERROR] Invalid options provided: $*; use -h for help;
cannot continue." >&2
exit 864
fi
while true; do
case "$1" in
-- ) shift ; break ;;
esac
done
# Do the job
#
if [[ "${HIDE_TABLE}" == "False" ]]; then
printf "\033[1;33m%s\033[m" "$($TS) [WARNING] It may be slow if you have many services as
srvctl is slow when a database has many services."
fi
export ORACLE_BASE=$(${ORACLE_HOME}/bin/orabase)
export PATH="${PATH}:${ORACLE_HOME}/bin"
else
. oraenv <<< $(ps -ef | grep pmon | grep asm | awk '{print $NF}' | sed s'/^.*_//') > /dev/null
2>&1
fi
printf "\033[1;31m%s\033[m" "$($TS) [ERROR] crsctl not found; please check that ASM is
correct in /etc/oratab; cannot continue."
exit 456
fi
for X in $(crsctl stat res -p -w "TYPE = ora.database.type" -attr "NAME,ORACLE_HOME" | awk -F "="
'{split($2,db,"."); getline; print db[2]":"$2}' | sort | uniq | grep -i "${GREP}" | grep -iv "${UNGREP}"
| grep -i "${DB}:"); do
SRVCTL="${OH}/bin/srvctl"
fi
COLOR_BEGIN = "\033[1;" ;
COLOR_END = "\033[m" ;
RED = "31m" ;
GREEN = "32m" ;
YELLOW = "33m" ;
BLUE = "34m" ;
TEAL = "36m" ;
WHITE = "37m" ;
COL_P = 12 ; # preferred
COL_A = 12 ; # Available
COL_F = 10 ; # Failback
COL_R = 12 ; # Role
function print_a_line(size) {
printf("%s", COLOR_END"\n") ;
return sprintf(COLOR_BEGIN color "%" left "s%s%" right "s" COLOR_END sep, "", str,
"" ) ;
# Get a string and return it with a nice case: first character in upper case ad the others
in lower case (ABCD => Abcd)
function nice_case(str) {
txt="" ;
oh=srvctl ;
txt=txt"export ORACLE_HOME="oh";"
txt=txt""sprintf("%s,", srvctl " " in_command " service -d " db " -s " S " -i "
temp_pref[k] " "in_force) ;
delete temp_pref ;
return txt ;
if ($0 ~ "is:running") {
tab_run[tolower($2)] = $NF ;
} else {
tab_run[tolower($2)] = "Offline" ;
END {
if (hide == "False") {
if (length(tab_svc) == 0) {
printf("%s", COLOR_END"\n") ;
exit ;
TAB_SIZE=COL_S+COL_P+COL_A+COL_F+COL_R+COL_RUN+7 ;
print_a_line(TAB_SIZE) ;
# Table header
printf("|%s\n" , "") ;
print_a_line(TAB_SIZE) ;
S=tab_svc_sorted[i] ;
if (badonly == "True") {
if (hide == "False") {
printf("|%-"COL_S"s", tab_svc[S]) ;
if (tab_run[S] != "") {
if (tab_pref[S] == tab_run[S]) {
RUN_COLOR=GREEN }
else {
RUN_COLOR=RED
if (tab_run[S] != "Offline") {
srvctl_commands=srvctl_commands""gen_srvctl(tab_avail[S], "stop" ,
force_opt) ;
if (hide == "False") {
printf("|%s\n" , "") ;
if (hide == "False") {
print_a_line(TAB_SIZE) ;
}
if (srvctl_commands != "" && topref == "True") {
if (hide == "False") {
printf("%s\n", temp[x]) ;
#printf("\n") ;
printf "\033[1;36m%s\033[m\n" "$($TS) [INFO] Restarting the services onto the preferred
instances, this can take some time . . ."
bash "${TEMP}"
if [ $? -eq 0 ]; then
else
fi
fi
rm -f "{TEMP}"
done