Here’s a quick and simple script which can help you to update a target property value of all targets running on a specific host. The script will expect you to enter 3 parameters: host name, property name and property value. Then it will search for the targets running on the given host name, and set the property to the given value:

emcli @setproperty.py hostname "propertyname" propertyvalue

It’s better to enter the property name in double quotes, because property names can contain spaces (for example “Line of Business”).

The script first checks the number of parameters, then login to OMS (enter your credentials – if you enter username but do not enter password, EMCLI will ask you to enter password when you run the script), gets the targets running on the given host (using EMCLI list command), and then executes set_target_property_value for each target. You may notice I give a non-default separator because some target names can contain colon (:) sign.

#
# Sample EMCLI Python script file for mass update a property value
#
# check number of arguments
if len(sys.argv) <> 3:
print 'Usage: emcli @setproperty.py hostname "propertyname" propertyvalue'
exit()

# assign the arguments to variables (for readability)
hostname = sys.argv[0]
propertyname = sys.argv[1]
propertyvalue = sys.argv[2]

# login to the OMS
login( username="SYSMAN", password="welcome1" )

# find the targets running on a given host
targets = list( sql="select target_name || '@' ||
target_type as target from MGMT$TARGET where host_name = '" + hostname + "' and target_name <> host_name" )

# set the target property for each target
for t in targets.out()['data']:
print "Setting property " + propertyname + " for " + t['TARGET'].split(':')[0]
set_target_property_value( property_records= t['TARGET'] + "@" + propertyname + "@" + propertyvalue, subseparator="property_records=@" )

About the Author

Gokhan Atil

Gokhan Atil has over 15 years of experience in the IT industry and a strong background in database management (Oracle 8i,9i,10g,11g), software development and UNIX systems. He is an Oracle certified professional for EBS R12, Oracle 10g and 11g. Gokhan specializes in high availability solutions, performance tuning and monitoring tools. Gokhan is a founding member and current vice president of Turkish Oracle User Group (TROUG). He’s also a member of Independent Oracle User Group (IOUG). Gokhan presented at various conferences, and he is one of co-authors of “Expert Oracle Enterprise Manager 12c” book.

Start the discussion at forums.toadworld.com