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):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# # Sample EMCLI Python script file to create users # # check number of arguments # if len(sys.argv) <> 1: print "Usage: emcli @create_users.py filename.csv" exit() # login to OMS # lg = login( username="SYSMAN" ) if lg.exit_code() <> 0: print lg.error() # open file for reading # f = open( sys.argv[0], 'r' ) # loop for each line of the file # for line in f: # split line to list (array) # sp = line.split(',') # # create user, save the file name as description # create_user( name=sp[0], password=sp[1], roles=sp[2], desc="Listed in " + sys.argv[0]) |
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:
1 2 3 4 |
Joe,oracle,em_all_operator William,oracle,EM_ALL_VIEWER Jack,oracle,EM_CLOUD_ADMINISTRATOR Averell,oracle,em_all_designer |
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
Foued
Amritap Datta
Gokhan Atil
Ravi kumar Pilla
Gokhan Atil
Ravi kumar Pilla
Gokhan Atil