EMCLI Python Script File to Create Users

I’ll give presentations at DOAG 2015 on Tuesday (tomorrow), and at the BGOUG Autumn Conference on Saturday. My presentation will be about EMCLI (Enterprise Manager Command Line Interface). I will try to explain the basics of EMCLI, its terminology, the important points, and how we can use it with bash for scripting. I’ll also speak about EMCLI Python scripting, very short but useful into to Python and then share some sample scripts. Because of the time limit of the session, I need to be picky about sample scripts and put only a few ones (which points important points). I’ll share more sample scripts on my blog. The following script shows how you can write an EMCLI script which will read usernames, passwords and roles from a CSV file and then create these users as EM administrators. This script must be used with “EMCLI with Scripting Mode” (aka advancedkit):

I think the code is self-explanatory. As you can see, the script accepts only one argument (the name of the CSV file containing the information of new users. The arguments can be accessed via sys.argv object. Then it logins to OMS (it will ask the password of SYSMAN. You can modify the script and add your EM administrator username and password. At line 18, it opens the file, at line 24, it starts to loop for each line in the file. We split the string to an array at line 27, and use the members of the array to create new users at line 31.

Here’s the sample CSV file:

By the way, I do not try to share “production quality” code. The sample code is just for guiding you to write better ones (for example: you may surely want to add exception handling etc…). If you have any questions about EMCLI Scripting, send them using contact form. I’ll be happy to answer them.

If you will attend to DOAG 2015 or BGOUG Autumn Conference, hope to see you in my session:
Jump into the EMCLI: A Crash Course for EM12c Administrators
Date: 2015-11-17 Time: 4:00 pm Room: Tokio
Jump into the EMCLI: A Crash Course for EM12c Administrators
Date: 2015-11-21 Time: 10:00 am Room: Hall B

Please share
  • 4

Gokhan Atil is a database administrator who has hands-on experience with both RDBMS and noSQL databases, and strong background on software development. He is certified as Oracle Certified Professional (OCP) and is awarded as Oracle ACE (in 2011) and Oracle ACE Director (in 2016) for his continuous contributions to the Oracle users community.


  1. Amritap Datta


    I need to pass user inputs in custom python script for emcli. When i use raw_input or input it is getting hung and not progressing. Is there a way?

    • Gokhan Atil

      Hi Amritap,

      When I try to get user input using raw_input function, it works as it expected. Which version do you use? Can you share the code you wrote (only the related part)?

Leave Comment

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