Database Reference
In-Depth Information
To establish a login in scripting mode, import the module from within the script being executed. For example,
the following script prints the total count of Enterprise Manager targets using an EM CLI function. But first it needs to
establish a login by importing the login module, as shown in Listing 3-10:
Listing 3-10. Establishing a login in scripting mode using the login module
import emcli
import login
mytargets = str(len(emcli.get_targets().out()['data']))
print(mytargets)
Task: Get a List of Targets
Viewing and manipulating Enterprise Manager targets are the most common uses of EM CLI. Regardless of which you
are doing, the first step is to retrieve the target information.
The get_targets verb or function retrieves a target list along with a number of other columns of information.
Neither the verb nor function requires parameters to retrieve the full list of information, as shown in Listing 3-11.
Listing 3-11. Retrieve the target information using command-line mode
[oracle ~]$ emcli login -username=sysman
Enter password :
Login successful
[oracle ~]$ emcli get_targets
Status Status Target Type Target Name ID
1 Up host oem.example.com
1 Up oracle_emd oem.example.com:3872
-9 n/a oracle_home common12c1_20_oem
The targets that are retrieved can be filtered by specifying a semi-colon-delimited list of target names and target
types, which should be separated by a colon. There should be no white space anywhere within the target list filter.
Listing 3-12 shows an example of creating a filter with two targets.
Listing 3-12. Limit the targets retrieved by get_targets using the targets parameter
[oracle ~]$ emcli get_targets \
-targets='oem.example.com:host;oms12c1_3_oem:oracle_home'
Status Status Target Type Target Name ID
1 Up host oem.example.com
-9 n/a oracle_home oms12c1_3_oem
The targets parameter can use wild cards anywhere within the target name or target type values, and multiple
wild cards can be used for either value, as shown in Listing 3-13.
 
Search WWH ::




Custom Search