{"id":2132,"date":"2012-06-22T08:44:18","date_gmt":"2012-06-22T13:44:18","guid":{"rendered":"http:\/\/jianmingli.com\/wp\/?p=2132"},"modified":"2012-07-24T15:12:40","modified_gmt":"2012-07-24T20:12:40","slug":"weblogic-11g-weblogic-scripting-tool-wlst","status":"publish","type":"post","link":"https:\/\/jianmingli.com\/wp\/?p=2132","title":{"rendered":"WebLogic 11g: WebLogic Scripting Tool (WLST)"},"content":{"rendered":"<span id=\"Overview\"><h2>Overview<\/h2><\/span>\n<p>* A command line scripting tools for WebLogic domain management:<br \/>\n&#8211; create<br \/>\n&#8211; manage<br \/>\n&#8211; monitor<br \/>\n* Based on Jython<\/p>\n<span id=\"WSLT_Online\"><h3>WSLT Online<\/h3><\/span>\n<p>* Is a JMX client<br \/>\n* Equivalent to Admin Console<br \/>\n&#8211; needs running Admin Server and active WebLogic domain<br \/>\n* Can<br \/>\n&#8211; view performance data<br \/>\n&#8211; manage security data<br \/>\n* Can NOT<br \/>\n&#8211; modify config data for managed servers<\/p>\n<span id=\"WSLT_Offline\"><h3>WSLT Offline<\/h3><\/span>\n<p>* Provides read\/write access to config data<br \/>\n* Should NOT be used on active WebLogic domain (ignored\/overwritten otherwise)<br \/>\n* Can<br \/>\n&#8211; create domain templates<br \/>\n&#8211; create a new domain based on existing templates<br \/>\n&#8211; extend an existing, inactive domain<br \/>\n* Can NOT<br \/>\n&#8211; view performance data<br \/>\n&#8211; modify security data<\/p>\n<span id=\"Command_Modes\"><h2>Command Modes<\/h2><\/span>\n<span id=\"Interactice_Mode\"><h3>Interactice Mode<\/h3><\/span>\n<span id=\"Script_Mode\"><h3>Script Mode<\/h3><\/span>\n<p>* Script needs <strong>.py<\/strong> file extension<br \/>\n* Can<br \/>\n&#8211; automate server config and application deployment<br \/>\n&#8211; apply same config setings across multiple nodes of a topology<br \/>\n&#8211; script scheduling<br \/>\n&#8211; automate complex procedures<br \/>\n&#8211; config an application in a hands free data center<\/p>\n<span id=\"Embedded_Mode\"><h3>Embedded Mode<\/h3><\/span>\n<p>* WLST interpreter is instantiated in Java code.<br \/>\n* WLST commands and scripts are then run from within Java code.<\/p>\n<span id=\"Secure_WLST_Connection\"><h2>Secure WLST Connection<\/h2><\/span>\n<span id=\"Admin_Port\"><h3>Admin Port<\/h3><\/span>\n<p>* WLST connects to a server instance via admin port.<br \/>\n* Default to 9002<br \/>\n* SSL enabled<\/p>\n<span id=\"Secure_Access_from_WLST_Online\"><h3>Secure Access from WLST Online<\/h3><\/span>\n<p>* Use user name and password as defined in the active WebLogic security realm.<br \/>\n&#8211; From command line<\/p>\n<pre lang=\"python\">\r\nconnect('weblogic', 'welcome1', 'localhost:7001')\r\n<\/pre>\n<p>&#8211; From password file<\/p>\n<pre lang=\"python\">\r\n# Prepare password files\r\nconnect('weblogic', 'welcome1', 'localhost:7001')\r\nstoreUserConfig('c:\/myFiles\/myuserconfigfile.secure',\r\n                          'c:\/myFiles\/myuserkeyfile.secure') \r\n\r\n# Use password files\r\nconnect(userConfigFile='c:\/myfiles\/myuserconfigfile.secure',\r\nuserKeyFile='c:\/myfiles\/myuserkeyfile.secure')\r\n<\/pre>\n<p>&#8211; Use boot.properties file<\/p>\n<pre lang=\"python\">\r\n# boot.properties file in current directory\r\nconnect()\r\n<\/pre>\n<span id=\"Main_Steps_for_Using_WLST_in_Interactive_or_Script_Mode\"><h2>Main Steps for Using WLST in Interactive or Script Mode<\/h2><\/span>\n<span id=\"Invoking_WLST\"><h3>Invoking WLST<\/h3><\/span>\n<p>* Execute the appropriate shell script for your environment.<br \/>\n&#8211; UNIX<\/p>\n<pre lang=\"bash\">\r\ncd WL_HOME\/common\/bin\r\n.\/wlst.sh\r\n<\/pre>\n<p>&#8211; Windows<\/p>\n<pre lang=\"bash\">\r\ncd WL_HOME\\common\\bin\r\nwlst.cmd\r\n<\/pre>\n<p>* Execute the java weblogic.WLST command.<\/p>\n<pre lang=\"bash\">\r\njava \r\n   [ -Dweblogic.security.SSL.ignoreHostnameVerification=true\r\n   -Dweblogic.security.TrustKeyStore=DemoTrust ]\r\n   [ -Dweblogic.security.JavaStandardTrustKeyStorePassPhrase=password]\r\n    [ -Dweblogic.security.CustomTrustKeyStoreFileName=filename\r\n     -Dweblogic.security.TrustKeystoreType=jks\r\n    [ -Dweblogic.security.CustomTrustKeyStorePassPhrase=password]]\r\n    [ -Dweblogic.security.SSL.hostnameVerifier=classname]\r\n   weblogic.WLST \r\n   [ -loadProperties propertyFilename ]\r\n   [ -skipWLSModuleScanning ]\r\n   [ [-i] filePath.py ] \r\n<\/pre>\n<p>&#8211; Example: <\/p>\n<pre lang=\"bash\">\r\njjava weblogic.WLST c:\/Oracle\/Middleware\/wlserver\/templates\/scripts\/wlst\/distributeQueues.py\r\n\r\njava -Dweblogic.security.SSL.ignoreHostnameVerification=true\r\n-Dweblogic.security.TrustKeyStore=DemoTrust weblogic.WLST\r\n c:\/Oracle\/Middleware\/wlserver\/templates\/scripts\/wlst\/distributeQueues.py \r\n<\/pre>\n<p>* Run a WLST script.<br \/>\n&#8211; Use Java command line:<\/p>\n<pre lang=\"bash\">\r\njava weblogic.WLST c:\/Oracle\/Middleware\/wlserver\/templates\/scripts\/wlst\/distributedQueues.py\r\n<\/pre>\n<p>&#8211; From WLST interactive mode:<\/p>\n<pre lang=\"bash\">\r\nwls:offline> execfile('c:\/Oracle\/Middleware\/wlserver\/templates\/scripts\/wlst\/distributedQueues.py')\r\n<\/pre>\n<p>* Execute the WebLogic Scripting Tool command from the Start menu (Windows only).<\/p>\n<p>* Running WLST from Ant.<br \/>\n&#8211; Set env:<br \/>\nWL_HOME\\server\\bin\\setWLSEnv.cmd (or setWLSEnv.sh on UNIX)<br \/>\n&#8211; Import task:<\/p>\n<pre lang=\"xml\">\r\n<taskdef name=\"wlst\" \r\n   classname=\"weblogic.ant.taskdefs.management.WLSTTask\" \/> \r\n<\/pre>\n<p>&#8211; Examples<\/p>\n<pre lang=\"xml\">\r\n<target name=\"configServer\"> \r\n   <wlst debug=\"false\" failOnError=\"false\" executeScriptBeforeFile=\"true\"  \r\n    fileName=\".\/myscript.py\"> \r\n       <classpath>\r\n         <pathelement location=\"${my.classpath.dir}\"\/>\r\n       <\/classpath>\r\n       <script>\r\n         connect('weblogic','welcome1','t3:\/\/localhost:7001') \r\n     <\/script> \r\n   <\/wlst> \r\n<\/target> \r\n<\/pre>\n<pre lang=\"xml\">\r\n<path id=\"my.classpath\">\r\n    <pathelement location=\"${my.classpath.dir}\"\/>\r\n<\/path>\r\n\r\n<target name=\"loop\"> \r\n  <wlst debug=\"true\" executeScriptBeforeFile=\"false\" \r\n    fileName=\".\/myscript.py\" failOnError=\"true\"> \r\n    <classpath>\r\n        <pathelement location=\"${my.classpath.dir}\"\/>\r\n    <\/classpath>\r\n    <script replaceProperties=\"true\">\r\n       print 'In the target loop' \r\n       connect('${admin.user}','${admin.password}','t3:\/\/localhost:7001') \r\n       svrs = cmo.getServers() \r\n       print 'Servers in the domain are' \r\n       for x in svrs: print x.getName()\r\n    <\/script>\r\n  <\/wlst> \r\n<\/target> \r\n<\/pre>\n<pre lang=\"xml\">\r\n<target name=\"error\"> \r\n   <wlst debug=\"true\" failOnError=\"false\"> \r\n      <script>print thisWillCauseNameError<\/script> \r\n   <\/wlst> \r\n<\/target>\r\n<\/pre>\n<span id=\"Exiting_WLST\"><h3>Exiting WLST<\/h3><\/span>\n<pre lang=\"bash\">\r\nwls:\/mydomain\/serverConfig> exit() \r\nExiting WebLogic Scripting Tool ... \r\n<\/pre>\n<span id=\"Syntax_for_WLST_Commands\"><h3>Syntax for WLST Commands<\/h3><\/span>\n<p>* Case sensitive.<br \/>\n* Enclose arguments in single or double quotes.<br \/>\n* Escape character: \\<br \/>\n* String as is: r<br \/>\n&#8211; Example: readTemplate(r&#8217;c:\\userdomains\\mytemplates\\mytemplate.jar&#8217;)<br \/>\n* If you need to cd to a management object whose name includes a forward slash (\/), surround the object name in parentheses.<br \/>\n&#8211; For example:cd(&#8216;JMSQueue\/(jms\/REGISTRATION_MDB_QUEUE)&#8217;)<\/p>\n<span id=\"Redirecting_Error_and_Debug_Output_to_a_File\"><h3>Redirecting Error and Debug Output to a File<\/h3><\/span>\n<p>* To redirect stdout, stderr to a file:<\/p>\n<pre>\r\nredirect(outputFile,[toStdOutAsWell])\r\n<\/pre>\n<p>* Stop redirect:<\/p>\n<pre>\r\nstopRedirect()\r\n<\/pre>\n<p>* Example:<\/p>\n<pre>\r\nwls:\/mydomain\/serverConfig> redirect('.\/logs\/wlst.log') \r\n<\/pre>\n<span id=\"Getting_Help\"><h3>Getting Help<\/h3><\/span>\n<pre>\r\nhelp\r\nhelp('online')\r\nhelp('offline')\r\nhelp('get*')\r\n<\/pre>\n<span id=\"Importing_WLST_as_a_Jython_Module\"><h3>Importing WLST as a Jython Module<\/h3><\/span>\n<p>* Invoke WLST:<\/p>\n<p>c:\\>java weblogic.WLST<br \/>\nwls:\/(offline)> <\/p>\n<p>* Use the writeIniFile command to convert WLST definitions and method declarations to a .py file:<\/p>\n<p>wls:\/(offline)> writeIniFile(&#8220;wl.py&#8221;)<br \/>\nThe Ini file is successfully written to wl.py<\/p>\n<p>* Open a new command shell and invoke Jython directly by entering the following command:<\/p>\n<p>c:\\>java org.python.util.jython <\/p>\n<p>* Import the WLST module into your Jython module using the Jython import command.<\/p>\n<p>>>>import wl <\/p>\n<p>*Now you can use WLST methods in the module. For example, to connect WLST to a server instance:<\/p>\n<p>wl.connect(&#8216;username&#8217;,&#8217;password&#8217;)<br \/>\n&#8230;. <\/p>\n<span id=\"Customizing_WLST\"><h3>Customizing WLST<\/h3><\/span>\n<p>* <\/p>\n<span id=\"Adding_Integrated_Help_for_Custom_Commands\"><h3>Adding Integrated Help for Custom Commands<\/h3><\/span>\n<p>* Define help text entries:<\/p>\n<pre>\r\n<commandName>_ShortDescription\r\n<commandName>_Description\r\n<commandName>_Example\r\n<commandName>_Syntax\r\n<\/pre>\n<p>* Example:<\/p>\n<pre>\r\nnavigate_ShortDescription=\\\r\n     Lists commands for navigating the hierarchy of beans.\r\nnavigate_Description=\\\r\n     \\n Navigates the hierarchy of beans and controls the prompt display. \\n\r\n<\/pre>\n<span id=\"\"><h3><\/h3><\/span>\n<p>* <\/p>\n<span id=\"_1\"><h3><\/h3><\/span>\n<p>* <\/p>\n<span id=\"_2\"><h3><\/h3><\/span>\n<p>* <\/p>\n<span id=\"References\"><h2>References<\/h2><\/span>\n<p>* <a href=\"http:\/\/download.oracle.com\/docs\/cd\/E17904_01\/web.1111\/e13715\/toc.htm\">Oracle\u00ae Fusion Middleware Oracle WebLogic Scripting Tool 11g Release 1 (10.3.4)<\/a><br \/>\n* <a href=\"http:\/\/download.oracle.com\/docs\/cd\/E17904_01\/web.1111\/e13813\/reference.htm\">Oracle\u00ae Fusion Middleware WebLogic Scripting Tool Command Reference 11g Release 1 (10.3.4)<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview * A command line scripting tools for WebLogic domain management: &#8211; create &#8211; manage &#8211; monitor * Based on Jython WSLT Online * Is a JMX client * Equivalent to Admin Console &#8211; needs running Admin Server and active &hellip; <a href=\"https:\/\/jianmingli.com\/wp\/?p=2132\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[104],"tags":[],"class_list":["post-2132","post","type-post","status-publish","format-standard","hentry","category-weblogic11g"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8cRUO-yo","_links":{"self":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/2132","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2132"}],"version-history":[{"count":5,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/2132\/revisions"}],"predecessor-version":[{"id":5471,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/2132\/revisions\/5471"}],"wp:attachment":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}