Database Reference
In-Depth Information
As we saw in the last chapter, each EM CLI session begins with two commands—login and sync. This same
practice should be followed when starting a session in a script. You could repeat the same sequence each time your
script starts a CLI session, like this:
emcli login -username="SYSMAN"-password=${
emcli sync
Since these two commands always execute together, they form the basis for a simple shell script function, seen
below. We'll look at some more-complex functions later in the chapter.
function EmcliLogin {
emcli login -username="SYSMAN" -password="${SECRET_PASSWORD}"
emcli sync
}
GetTargetName Function
In the previous chapter we explained how the get_targets verb can be used to determine the exact name of an OEM
target. Since shell scripts are built to handle edge cases, like missing directories, any target-manipulation script should
verify the following:
1.
The target exists in OEM.
2.
You use the exact name of the target in your CLI command.
Build the get_targets verb into a function by giving it a name and wrapping the commands in braces. In this
example the value for INPUT_VAL is passed into the function by the calling script:
function GetTargetName {
if [ `emcli get_targets | grep ${INPUT_VAL}%"| grep oracle_database" | wc -l` -gt 0 ];
then
thisTARGET=`emcli get_targets -format -name="name:csv"| grep -i ${INPUT_VAL} | grep
oracle_database | cut -d, -f4`
echo "Target name is ${thisTARGET}"
else
echo "No matching targets found"
fi
}
In this example, we set a variable named thisTARGET for the exact target name known to OEM for the Oracle
database acme_qa . At run-time, the target name will be passed from the command line or through additional scripting
(working through a list of targets, for instance). The steps outlined here are explained in detail later.
1.
Determine first whether a matching target exists.
If it does exist, set the variable thisTARGET to match and announce your success. Logging
and interactive user communication are essential to troubleshooting shell scripts. Share
the status whenever new information is available at run-time.
2.
3.
If it does not exist, fail loudly and politely. One of the core Unix programming rules is
that programs should fail as early as possible and loudly as possible. Shell scripts are no
exception.
 
Search WWH ::




Custom Search