Database Reference
In-Depth Information
The next example shows how to further manipulate a list by extracting and deleting the last element of
myshortlist . The first command in this example does three things. The pop function extracts and then deletes from
mylist the last element, creates the myshortlist list object, and assigns to it the “popped” element. If the pop()
function weren't preceded by an object assignment, it would simply print the element:
>>> myshortlist = mylist.pop()
>>> print(myshortlist)
six
>>> print(mylist)
['one', 'two', 'three', 'four', 'five']
Lists in EM CLI
Lists play a critical role in EM CLI. The output of the functions in EM CLI may produce a list with hundreds or even
thousands of elements, and those elements may be composed of strings, numbers, or other objects. The lists in EM
CLI work in exactly the same way that they do in the previous examples.
Understanding everything about the following example is not important right now, but it is important to note
that the list() function is one of the most-used functions in EM CLI and always returns a list object. This list has 29
elements that can be “popped” off one at a time and assigned to another object:
emcli>mytargs = list(resource='Targets').out()['data']
emcli>type(mytargs)
<type 'list'>
emcli>len(mytargs)
29
emcli>myshorttargs = mytargs.pop()
emcli>print(myshorttargs)
{'TYPE_DISPLAY_NAME': 'Oracle WebLogic Server', 'TYPE_QUA...
The output of the list EM CLI function is a list of target information.
Strings and Lists
This section will show how to accomplish the common task of finding a running Oracle database listener in Linux
by using the Linux ps and grep commands. The first part of the example will show how to produce the process
information. The second part of the example will show how to parse the output of the ps command using various
Linux utilities, followed by the use of Python to accomplish the same task.
Listing 6-1 shows a detailed listing of an Oracle database listener background process. The ps -ef command lists
all of the running processes on the server, which are piped into grep to limit the output to just the listener processes.
Listing 6-1. Find the Oracle database listener process in Linux
[oracle@server ]$ ps -ef | grep [t]nslsnr
oracle 1723 1 0 16:21 ? 00:00:01
/u01/app/oracle/product/12.1.0/dbhome_1/bin/tnslsnr LISTENER -inherit
The combination of ps and grep shows that a single listener is running and shows the full command in the eighth
column of the output. The listener command actually includes two spaces, so to us it looks like the command spans
the eighth, ninth, and tenth space-delimited columns. The awk command parses this information quite well, as shown
in Listing 6-2.
 
Search WWH ::




Custom Search