Database Reference
In-Depth Information
Creating and Using a Function Library
The previous example assumes that everything goes well with the refresh and that OEM resumes monitoring after
an hour. Of course, the blackout will end six hours after it starts, even without end_blackout.sh . Why not turn off the
blackout right after the work is done?
Converting this activity to shell functions in a central library allows you to start and stop the blackout inside the
restore_training.sh script, as shown here:
#!/bin/sh
# =====================================================
# File: restore_training.sh
# Purpose: Refresh database from a cold backup copy of datafiles
# Parameters: Database name as ORASID
# =====================================================
# Source the OEM function library
. /script/oem/emcli_functions.lib
export BO_NAME=database_refresh_${ORASID}
CreateBlackout
< Existing your in-house database restoration commands >
EndBlackout
Only one cron entry (or OEM scheduled job) is required because you've wrapped the work of all three scripts into
one wrapper.
The function library sourced in this example contains the functions CreateBlackout and EndBlackout . The
function library is simply a non-executable text file stored in a central location on each server, preferably through NFS
mounts or a similar shared file system.
This snippet only contains the two functions relevant to this example. Chapter 8 contains an example of a
complete function library. Your production CLI function library can contain many others, in addition to these two.
Notice that the contents of the functions are identical to the code we used in the separate shell scripts. They're just
recorded as functions.
# =====================================================
# File: emcli_functions.lib
# Purpose: Shared function library for EM CLI scripts
# Note : Source this library to load its contents into memory
# =====================================================
function CreateBlackout {
echo "\n\nCreating blackout named '${BO_NAME}' ...\n"
if [ `emcli get_blackouts | grep ${BO_NAME} | wc -l` -gt 0 ]; then
echo "\n\nFound an existing blackout named ${BO_NAME}"
echo "That blackout will be stopped and deleted prior to starting the new one\n\n"
emcli stop_blackout -name="${BO_NAME}"
emcli delete_blackout -name="${BO_NAME}"
fi
 
Search WWH ::




Custom Search