Friday, May 17, 2013

Shell script $# $@ $- $$

Command Line Arguments


Command line arguments are treated as special variables within the script, the reason I am calling them variables is because they can be changed with the shift command. The command line arguments are enumerated in the following manner $0, $1, $2, $3, $4, $5, $6, $7, $8 and $9. $0 is special in that it corresponds to the name of the script itself. $1 is the first argument, $2 is the second argument and so on. To reference after the ninth argument you must enclose the number in brackets like this ${nn}. You can use the shift command to shift the arguments 1 variable to the left so that $2 becomes $1, $1 becomes $0 and so on, $0 gets scrapped because it has nowhere to go, this can be useful to process all the arguments using a loop, using one variable to reference the first argument and shifting until you have exhausted the arguments list.



As well as the commandline arguments there are some special builtin variables:



•$# represents the parameter count. Useful for controlling loop constructs that need to process each parameter.



•$@ expands to all the parameters separated by spaces. Useful for passing all the parameters to some other function or program.



•$- expands to the flags(options) the shell was invoked with. Useful for controlling program flow based on the flags set.



•$$ expands to the process id of the shell innovated to run the script. Useful for creating unique temporary filenames relative to this instantiation of the script.



Note

The commandline arguments will be referred to as parameters from now on, this is because SH also allows the definition of functions which can take parameters and when called the $n family will be redefined, hence these variables are always parameters, its just that in the case of the parent script the parameters are passed via the command line. One exception is $0 which is always set to the name of the parent script regardless of whether it is inside a function or not.





Tuesday, April 30, 2013

WLST Overview


http://jianmingli.com/wp/?p=2132


Overview


* A command line scripting tools for WebLogic domain management:

- create

- manage

- monitor

* Based on Jython



WSLT Online

* Is a JMX client

* Equivalent to Admin Console

- needs running Admin Server and active WebLogic domain

* Can

- view performance data

- manage security data

* Can NOT

- modify config data for managed servers



WSLT Offline

* Provides read/write access to config data

* Should NOT be used on active WebLogic domain (ignored/overwritten otherwise)

* Can

- create domain templates

- create a new domain based on existing templates

- extend an existing, inactive domain

* Can NOT

- view performance data

- modify security data



Command Modes

Interactice Mode

Script Mode

* Script needs .py file extension

* Can

- automate server config and application deployment

- apply same config setings across multiple nodes of a topology

- script scheduling

- automate complex procedures

- config an application in a hands free data center



Embedded Mode

* WLST interpreter is instantiated in Java code.

* WLST commands and scripts are then run from within Java code.



Secure WLST Connection

Admin Port

* WLST connects to a server instance via admin port.

* Default to 9002

* SSL enabled



Secure Access from WLST Online

* Use user name and password as defined in the active WebLogic security realm.

- From command line





connect('weblogic', 'welcome1', 'localhost:7001')

- From password file





# Prepare password files

connect('weblogic', 'welcome1', 'localhost:7001')

storeUserConfig('c:/myFiles/myuserconfigfile.secure',

'c:/myFiles/myuserkeyfile.secure')



# Use password files

connect(userConfigFile='c:/myfiles/myuserconfigfile.secure',

userKeyFile='c:/myfiles/myuserkeyfile.secure')

- Use boot.properties file





# boot.properties file in current directory

connect()

Main Steps for Using WLST in Interactive or Script Mode

Invoking WLST

* Execute the appropriate shell script for your environment.

- UNIX





cd WL_HOME/common/bin

./wlst.sh

- Windows





cd WL_HOME\common\bin

wlst.cmd

* Execute the java weblogic.WLST command.





java

[ -Dweblogic.security.SSL.ignoreHostnameVerification=true

-Dweblogic.security.TrustKeyStore=DemoTrust ]

[ -Dweblogic.security.JavaStandardTrustKeyStorePassPhrase=password]

[ -Dweblogic.security.CustomTrustKeyStoreFileName=filename

-Dweblogic.security.TrustKeystoreType=jks

[ -Dweblogic.security.CustomTrustKeyStorePassPhrase=password]]

[ -Dweblogic.security.SSL.hostnameVerifier=classname]

weblogic.WLST

[ -loadProperties propertyFilename ]

[ -skipWLSModuleScanning ]

[ [-i] filePath.py ]

- Example:





jjava weblogic.WLST c:/Oracle/Middleware/wlserver/templates/scripts/wlst/distributeQueues.py



java -Dweblogic.security.SSL.ignoreHostnameVerification=true

-Dweblogic.security.TrustKeyStore=DemoTrust weblogic.WLST

c:/Oracle/Middleware/wlserver/templates/scripts/wlst/distributeQueues.py

* Run a WLST script.

- Use Java command line:





java weblogic.WLST c:/Oracle/Middleware/wlserver/templates/scripts/wlst/distributedQueues.py

- From WLST interactive mode:





wls:offline> execfile('c:/Oracle/Middleware/wlserver/templates/scripts/wlst/distributedQueues.py')

* Execute the WebLogic Scripting Tool command from the Start menu (Windows only).



* Running WLST from Ant.

- Set env:

WL_HOME\server\bin\setWLSEnv.cmd (or setWLSEnv.sh on UNIX)

- Import task:






classname="weblogic.ant.taskdefs.management.WLSTTask" />

- Examples








fileName="./myscript.py">

























fileName="./myscript.py" failOnError="true">

























Exiting WLST



wls:/mydomain/serverConfig> exit()

Exiting WebLogic Scripting Tool ...

Syntax for WLST Commands

* Case sensitive.

* Enclose arguments in single or double quotes.

* Escape character: \

* String as is: r

- Example: readTemplate(r'c:\userdomains\mytemplates\mytemplate.jar')

* If you need to cd to a management object whose name includes a forward slash (/), surround the object name in parentheses.

- For example:cd('JMSQueue/(jms/REGISTRATION_MDB_QUEUE)')



Redirecting Error and Debug Output to a File

* To redirect stdout, stderr to a file:



redirect(outputFile,[toStdOutAsWell])

* Stop redirect:



stopRedirect()

* Example:



wls:/mydomain/serverConfig> redirect('./logs/wlst.log')

Getting Help

help

help('online')

help('offline')

help('get*')

Importing WLST as a Jython Module

* Invoke WLST:



c:\>java weblogic.WLST

wls:/(offline)>



* Use the writeIniFile command to convert WLST definitions and method declarations to a .py file:



wls:/(offline)> writeIniFile("wl.py")

The Ini file is successfully written to wl.py



* Open a new command shell and invoke Jython directly by entering the following command:



c:\>java org.python.util.jython



* Import the WLST module into your Jython module using the Jython import command.



>>>import wl



*Now you can use WLST methods in the module. For example, to connect WLST to a server instance:



wl.connect('username','password')

....



Customizing WLST

*



Adding Integrated Help for Custom Commands

* Define help text entries:



_ShortDescription

_Description

_Example

_Syntax

* Example:



navigate_ShortDescription=\

Lists commands for navigating the hierarchy of beans.

navigate_Description=\

\n Navigates the hierarchy of beans and controls the prompt display. \n

*



*



*



Monday, April 29, 2013

This script is used the check the health of the heap in weblogic server 11g

There are two script

1. Shell script whihc will call a python
2. Python Script


1. Shell Script : heap_status.sh

#!/bin/bash


#Author Mohammed Ashraf TP

#Date APRIL 08 2013

# ************* Setting the Environment ***********************

PAR_SLICE=`whoami `

echo $PAR_SLICE

SLICE=`echo $PAR_SLICE
cut -c4-8`

echo $SLICE

SOA_USER=soa_"$SLICE"

echo $SOA_USER

SOA_DOMAIN_NAME=soa_"$SLICE"_Domain

echo $S0A_DOMAIN_NAME







DOMAIN_HOME="/var/domain/"$SOA_USER"/"$SOA_DOMAIN_NAME"/"

echo $DOMAIN_HOME

. ${DOMAIN_HOME}/bin/setDomainEnv.sh $*



export CLASSPATH=/var/domain/"$PAR_SLICE"/WEBLOGIC_HOME/server/lib/weblogic.jar



echo "Environment has been set....."



# ************* Changing the directory where all the related files are needed ***********************



echo "Calling the PYTHON script....."



# ************* Calling the WLST script *****************



export CONFIG_JVM_ARGS="-Dweblogic.security.SSL.ignoreHostnameVerification=true -Dweblogic.security.TrustKeyStore=CustomTrust -Dweblogic.security.CustomTrustKeyStoreFileName=/var/domain/"$SOA_USER"/keystore/WebLogicTrustKeyStore.jks -Dweblogic.security.CustomTrustKeyStorePassPhrase=password -Dweblogic.security.CustomTrustKeyStoreType=JKS -Dweblogic.security.SSL.allowSmallRSAExponent=true"



echo $CONFIG_JVM_ARGS

/opt/Oracle/Middleware/Oracle_SOA1/common/bin/wlst.sh /home/"$PAR_SLICE"/WLST_TP/Health_Check/heap_status.py

    ++++++++++++++++++++++++++++++++++++++++++++++++++ 2.Python Script :heap_status.py   #Definition for connecting to a server

#!/usr/bin/python

from java.io import FileInputStream

from java.util import *

from javax.management import *

import sys

import re

import os

import pdb



def connectToServer():

username = 'weblogic'

password = 'password'

url = 't3s://mlx555:7777'

connect(username, password, url)



#Definition to print a running servers heap details

def printHeapDetails(server_name):

domainRuntime()

cd('/')

cd('ServerRuntimes/'+server_name+'/JVMRuntime/'+server_name)

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

def disconnectFromServer():

disconnect()

exit()



#Calling connectToServer definition with no arguments

connectToServer()



#Calling printHeapDetails with arguments

printHeapDetails('soa_dev04_AdminServer01')

printHeapDetails('soa_dev04_BusinessServer01')

#printHeapDetails('mgds2')



#Calling disconnectFromServer definition with no arguments

disconnectFromServer()

Monday, April 15, 2013

command to delete control m character

sed -i -e 's/^/rm -rf /' toDelete.sh

cut command ...

Write a script called mycut.sh
And invoke the script using mycut.sh android


Snippets of mycut.sh is given below
===================
PAR_SLICE=$1


SLICE=`echo $PAR_SLICE
cut -c4-7`

echo $SLICE

SOA_USER=soa_"$SLICE"

echo $SOA_USER

SOA_DOMAIN_NAME=soa_"$SLICE"_Domain

echo $S0A_DOMAIN_NAME

================ Execute :   ./mycut.sh android   =============== Output roid soa-roid soa_roid_Domain    

Friday, April 5, 2013

Auomation of "Mapping of Logical Role to BPM Roles"

Script to automate "Logical group to BPM Access role mapping" is working succesfully .




Please find the below location of the script name and the syntax to execute the script



Location : /home/soast01/WLST_TP/Create_AccessRoles

Script Name : Create_AccessRoles_BPM.sh





Note:



Please modify the property file /home/soast01/WLST_TP/Create_AccessRoles/Access_Role.properties, according to the requirement ..







To test I am trying to add 2 groups

1. gr gg  usr eur Level 2_DIT ,

2. gr gg usr eur Level 3_DIT

to the BPM Process Role -> CreateTelephoneApplication.CustomerService



So in this case we have to modify the property file Access_Role.properties, with the above 2 groups and the BPM Process Role

groups gr gg usr eur Level 2_DIT , gr gg usr eur Level 3_DIT to the BPM Process Role , CreateTelephoneApplication.CustomerService .

Also Admin URL,username , password and total number of groups should be mentioned .





Syntax :



Create_AccessRoles_BPM.sh



1. cat //WLST_TP/Create_AccessRoles/Access_Role.properties

admin.url=t3s://mlx123:25454

admin.userName=weblogic

admin.password=pwd



total.GROUPS=3



group.name.1 = gr gg usr eur Level 2_DIT



user.soarole.1 = CreateApplication.CustomerService





user.soarole.2 = CreateApplication.CustomerService

group.name.2 = gr gg usr eur Level 3_DIT



#Comma seperated roles

2.  cat Create_AccessRoles_BPM.sh

#!/bin/bash

#Author Mohammed Ashraf TP

#Date MARCH 18 2013

# ************* Setting the Environment ***********************

DOMAIN_HOME="/var/domain/soa_st01/soa_st01_Domain/"

. ${DOMAIN_HOME}/bin/setDomainEnv.sh $*



export CLASSPATH=/var/domain/soa_st01/WEBLOGIC_HOME/server/lib/weblogic.jar



echo "Environment has been set....."



# ************* Changing the directory where all the related files are needed ***********************

cd /home/soa01/WLST_TP/Create_AccessRoles



echo "Calling the PYTHON script....."



# ************* Calling the WLST script *****************



export CONFIG_JVM_ARGS="-Dweblogic.security.SSL.ignoreHostnameVerification=true -Dweblogic.security.TrustKeyStore=CustomTrust -Dweblogic.security.CustomTrustKeyStoreFileName=/var/domain/soa_01/keystore/TrustKeyStore.jks -Dweblogic.security.CustomTrustKeyStorePassPhrase=wpwd -Dweblogic.security.CustomTrustKeyStoreType=JKS -Dweblogic.security.SSL.allowSmallRSAExponent=true"



/opt/Oracle/Middleware/Oracle_SOA1/common/bin/wlst.sh /home/soa/WLST_TP/Create_AccessRoles/AccessRoles_BPM.py $1 $2 $3


3.
[soast01@ngmlx476 Create_AccessRoles]$ cat AccessRoles_BPM.py


#!/usr/bin/python



from java.io import FileInputStream



from java.util import *



from javax.management import *



import sys



import re



import os



import pdb



propInputStream = FileInputStream("/home/soast01/WLST_TP/Create_AccessRoles/Access_Role.properties")



configProps = Properties()



configProps.load(propInputStream)



adminURL=configProps.get("admin.url")



adminUserName=configProps.get("admin.userName")



adminPassword=configProps.get("admin.password")



totalnumberofGROUPS=configProps.get("total.GROUPS")



connect(adminUserName, adminPassword, adminURL)



domainRuntime()



print 'Adding SOA Roles Membership of the Users:'



counter = 1



print counter



print totalnumberofGROUPS



print adminURL

print adminUserName

print adminPassword



count = 1

while count < int(totalnumberofGROUPS):

roleName = configProps.get("user.soarole." + str(count))

#groupName = configProps.get("group.name." + str(count)).split(",")

groupName = configProps.get("group.name." + str(count))

count = count + 1

print roleName

print groupName

grantAppRole(appStripe="OracleBPMProcessRolesApp",appRoleName=roleName ,principalClass="weblogic.security.principal.WLSGroupImpl",principalName=groupName)





disconnect()



exit()

How to display only Permissions and file names using ls command?

find /path -printf "%f:%p:%u:%g:%m\n"