Using cloud control (emcli) to run command on remote server(s)

emcli is an incredibly powerful tool and i get the impression that not many sites make full (if any) use of its functionality. This post is just to illustrate how simple and useful some of these features are. In this example i'm going to use it to execute a shell script on 2 remote servers (you can of source do this with ssh equivalence and other means) but cloud control makes this very easy especially on windows platforms.

To be able to use the emcli functionality you need to have preferred credentials saved for the user you want to run the command as.

To set these up (if you haven't already) navigate to the security to the setup->security->preferred credentials screen (shown below)

Then set credentials for all of the servers you want to access

Once that is all in place you can then go to the emcli command line and do the following:

[oracle@host]:OMS12c:[~]# emcli login -username=your-cloud_control-login
Enter password :

Login successful

Then  you can execute the command

[oracle@host]:OMS12c:[~]# emcli execute_hostcmd -cmd="/tmp/" -targets="remote-host:host"
* Target: remote-host:host
* Execution Status: Succeeded

* Execution Summary
*     Targets Succeeded: 1
*         remote-host:host
*     Targets Failed: 0

If you want to run against multiple hosts you can just seperate them with a ';' or you can run the job against a group object instead.

[oracle@host]:OMS12c:[~]# emcli execute_hostcmd -cmd="/tmp/" -targets="remhost1:host;remhost2:host"

All of this can alos be executed via the gui of course as a scheduled job as well.


Post a Comment