Install EM13c agent and add targets using the Linux command line only

A few days ago, I was asked to find a way to automate the addition of newly created Linux virtual machines and databases in our EM13c console. Of course, no action should be performed via the EM web interface!

For the first part (installing the EM13c agent on newly created virtual machines), it’s quite simple, because Oracle gives you many methods (for example, “agent pull” method), in order to carry out this task. But the second part seemed more delicate according to the documentation and my constraints: everything must be done on the virtual machine. I am not allowed to connect to the EM server using SSH.

Fortunately, there is a simple solution that only requires a few extra lines in your shell script!

I will not give you my entire script because it is very specific to the environment, but I will give you the main steps and the code you need to know.


Here’s a list of what you need to know before going any further. I give you the values ​​for my environment because I will use them in the next chapters.


  • OMS host: oem13c.local
  • EM Upload Port: 4903
  • EM Console Port: 7803
  • EM User: SYSMAN
  • EM User password & Agent Registration Password: welcome1


  • Agent host (hostname of my newly created virtual machine): linuxlab01.local
  • Agent owner: oracle
  • Agent version:
  • Agent platform: Linux x86-64
  • Agent port: 3872
  • Agent base directory: /app/oracle/product/agent13c
  • Agent instance home: /app/oracle/product/agent13c/agent_inst

Oracle installation

  • ORACLE_HOME: /app/oracle/product/12.1.0
  • Listener name: LISTENER
  • Listener port: 1521
  • EM User: DBSNMP
  • EM User password: welcome1

That’s a lot of information, but you will need each of them.

Agent installation

For an overview of all available possibilities, please read the Oracle documentation about installing Oracle Management Agent in silent mode.

In my case, I opted for the “AgentPull Script” method.

The EM agent will be installed into “/app/oracle/product/agent13c”. The directory must exist and be empty. Be careful: oracle (or the account you will use to own the agent installation) must have all privileges on this directory!

Unless mentioned, each step is performed with the owner of the agent installation.

Response file creation

First, you must create a response file that will be passed as a parameter to the “AgentPull” script. You need to replace the values according to your environment.

[oracle@linuxlab01]# cat /tmp/em_agent.rsp
PLATFORM="Linux x86-64"

Download the “” script from OMS

The script is available and directly downloadable from your OMS server.

[oracle@linuxlab01]# curl -sk https://oem13c.local:7803/em/install/getAgentImage > /tmp/
[oracle@linuxlab01]# chmod 755 /tmp/

EM agent installation

You just have to execute one command:

[oracle@linuxlab01]# /tmp/ -ignorePrereqs RSPFILE_LOC=/tmp/em_agent.rsp

If everything worked fine, you will see the following line at the end of the script execution:

Successfully Promoted agent and its related targets to Management Agent

You can also test the return code as usual with the special variable “$?” . execution

To complete the installation, you must run the “” script as “root” user, as indicated in the installation log:

[root@linuxlab01]# /app/oracle/product/agent13c/agent_13.

At this point, you server is visible in your EM13c console but you need additional steps to add your database(s) and your listener(s).

Resources addition

The easiest and fastest way I found to add resources to EM13c from a server is to deploy a temporary emcli client, add the targets, and delete it.

The Emcli client is quite lightweight(5MB) and only needs less than 2 minutes to be operational, so it does not represent a significant overhead in your shell script. Like the “” script, it can be downloaded directly from your OMS server.

Download and install emcli

Nothing complicated here: the emcli client is downloaded from the OMS server and then, installed in “/tmp/emcli”.

[oracle@linuxlab01]# export JAVA_HOME=/app/oracle/product/agent13c/agent_13.
[oracle@linuxlab01]# mkdir -p /tmp/emcli/conf
[oracle@linuxlab01]# wget -P /tmp/emcli --quiet --no-check-certificate https://oem13c.local:7803/em/public_lib_download/emcli/kit/emclikit.jar
[oracle@linuxlab01]# ${JAVA_HOME}/bin/java -jar /tmp/emcli/emclikit.jar -install_dir=/tmp/emcli

Configure emcli client

Once downloaded and installed, you need to configure emcli in order to connect it with your OMS server. A lot of options are available, you can find an entire list on Oracle documentation.

In my case, the only important option is “noregister“. Since I will delete the emcli client after adding the resources, I do not want my OMS server to keep track about its installation.

[oracle@linuxlab01]# /tmp/emcli/emcli setup -url=https://oem13c.local:7803/em -username="sysman" -password="welcome1" -dir="/tmp/emcli/conf" -trustall -noregister -noautologin

Create a “commands file” for emcli

Because I want to keep track of the generated commands in case of a problem, I chose to put the addition commands in a text file and then pass the file as an argument to emcli.

[oracle@linuxlab01]# echo "add_target -name=\"linuxlab01.local_listener\" -type=\"oracle_listener\" -host=\"linuxlab01.local\" -properties=\"LsnrName:LISTENER;ListenerOraDir:/app/oracle/product/12.1.0/network/admin;Port:1521;OracleHome:/app/oracle/product/12.1.0;Machine:linuxlab01.local;\"" >> "/tmp/emcli/emclicommands.txt"

[oracle@linuxlab01]# echo "add_target -name=\"linuxlab01.local_ORCL\" -type=\"oracle_database\" -host=\"linuxlab01.local\" -credentials=\"UserName:dbsnmp;password:welcome1;Role:Normal\" -properties=\"SID:ORCL;Port:1521;OracleHome:/app/oracle/product/12.1.0;MachineName:linuxlab01.local;\"" >> "/tmp/emcli/emclicommands.txt"

The “-name” parameter is the name under which the resource will appear in EM13c. It must be unique, that’s why I’m adding the hostname in it.

Execute the command file

The last step is to run the generated command file via emcli and remove the emcli directory.

[oracle@linuxlab01]# /tmp/emcli/emcli sync
[oracle@linuxlab01]# /tmp/emcli/emcli argfile /tmp/emcli/emclicommands.txt
[oracle@linuxlab01]# rm -rf /tmp/emcli/

After a while (15 minutes on my installation), the targets will be visible from your EM13c web console or via emcli queries 🙂

I hope you find this articled useful. Stay tuned for more DBA stuff!

Leave a Reply

Your email address will not be published. Required fields are marked *