Let us see an example of a using definition in the same script.
#Definition for connecting to a server
username = 'weblogic'
password = 'weblogic'
url = 't3://egAdm:7001'
connect(username, password, url)
#Definition to print a running servers heap details
hf = float(get('HeapFreeCurrent'))/1024
hs = float(get('HeapSizeCurrent'))/1024
hf = hf/1024
hs = hs/1024
print 'HeapFreeCurrent - ' + `hf` + 'MB'
print 'HeapSizeCurrent - ' + `hs` + 'MB'
#Definition to disconnect from a server
#Calling connectToServer definition with no arguments
#Calling printHeapDetails with arguments
#Calling disconnectFromServer definition with no arguments
In the above script we are connecting to the administration server of a domain and then printing the heap details for the admin server and 2 other managed servers. The logic to navigate to the respective runtime mbean and printing the heap related attributes is being defined as reusable definition and called multiple times.
WLST-BP-4 Use definitions for Reuse