Wednesday, July 29, 2009

INITTAB changes

In case you make changes to inittab file you need not reboot the system. You can gibe below command to make the chane effective.

kill -HUP 1

This will make effect the change you have made.

Monday, July 27, 2009

Grinder Load Testing Framework

1) To start the agent issue below command
java -cp "E:\apps\grinder-3.2\grinder-3.2\lib\grinder.jar" net.grinder.Grinder

2) To start the console
java -cp "E:\apps\grinder-3.2\grinder-3.2\lib\grinder.jar" net.grinder.Console

You have to set classpath for grinder.jar and jython.jar before this.

This assumes grinder is installed at E:\apps\grinder-3.2

Use TCPProxy to create a macro of the activity of testing

Here is a sample grinder.properties file

grinder.logDirectory=log
grinder.threads=5
grinder.processes=1
grinder.runs=0
grinder.script=mailcom.py

Saturday, July 25, 2009

Swing Frame using Jython

from javax.swing import JButton, JFrame

class MyFrame(JFrame):
def __init__(self):
JFrame.__init__(self, "Hello Jython")
button = JButton("Hello", actionPerformed=self.hello)
self.add(button)

self.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
self.setSize(300, 300)
self.show()

def hello(self, event):
print "Hello, world!"

if __name__=="__main__":
MyFrame()

Swing using Jython

from java import awt
from pawt import swing

labels = ['7', '8', '9', '+',
'4', '5', '6', '-',
'1', '2', '3', '*',
'0', '.', '=', '/' ]

keys = swing.JPanel(awt.GridLayout(4, 4))
display = swing.JTextField()

def push(event): # Callback for regular keys
display.replaceSelection(event.actionCommand)

def enter(event): # Callback for '=' key
display.text = str(eval(display.text))
display.selectAll()

for label in labels:
key = swing.JButton(label)
if label == '=':
key.actionPerformed = enter
else:
key.actionPerformed = push
keys.add(key)

panel = swing.JPanel(awt.BorderLayout())
panel.add("North", display)
panel.add("Center", keys)
swing.test(panel)

Swing using Jython

from java import awt
from pawt import swing

labels = ['7', '8', '9', '+',
'4', '5', '6', '-',
'1', '2', '3', '*',
'0', '.', '=', '/' ]

keys = swing.JPanel(awt.GridLayout(4, 4))
display = swing.JTextField()

def push(event): # Callback for regular keys
display.replaceSelection(event.actionCommand)

def enter(event): # Callback for '=' key
display.text = str(eval(display.text))
display.selectAll()

for label in labels:
key = swing.JButton(label)
if label == '=':
key.actionPerformed = enter
else:
key.actionPerformed = push
keys.add(key)

panel = swing.JPanel(awt.BorderLayout())
panel.add("North", display)
panel.add("Center", keys)
swing.test(panel)

Friday, July 24, 2009

Awk script to create Insert statements

#!/usr/bin/awk -f
BEGIN {
# change the record separator from newline to nothing
#RS=""
# change the field separator from whitespace to newline
#FS="n"

}
{
# print the second and third line of the file
if ($1=="") $1 = "NULL";
if ($2=="") $2 = "NULL";
if ($3=="") $3 = "NULL";
if ($4=="") $4 = "NULL";
print "insert into mytable (someno,sequance,1_id1,2_id2,3_id3)values(501," NR "," $2 "," $3 "," $4")
;"


}
END {

}

Thursday, July 23, 2009

Advanced Solaris Command

Process stats
– cputrack - per-processor hw counters
– pargs – process arguments
– pflags – process flags
– pcred – process credentials
– pldd – process's library dependencies eg.pldd `pgrep syslog`
– psig – process signal disposition
– pstack – process stack dump eg. pstack `pgrep syslog`
– pmap – process memory map
– pfiles – open files and names
– prstat – process statistics
– ptree – process tree
– ptime – process microstate times
– pwdx – process working directory



Process control
– pgrep – grep for processes
– pkill – kill processes list
– pstop – stop processes
– prun – start processes
– prctl – view/set process resources
– pwait – wait for process
– preap – reap a zombie process
- pfiles - Find Files Opened by a Process eg. pfiles `pgrep syslog` | pg


Process tracing/debugging
– abitrace – trace ABI interfaces
– dtrace – trace the world
– mdb – debug/control processes
– truss – trace functions and
system calls



Kernel tracing/debugging
– dtrace – trace and monitor kernel
– lockstat – monitor locking statistics
– lockstat -k – profile kernel
– mdb – debug live and kernel cores



System stats
– acctcom – process accounting
– busstat – Bus hardware counters
– cpustat – CPU hardware counters
– iostat – IO & NFS statistics
– kstat – display kernel statistics
– mpstat – processor statistics
– netstat – network statistics
– nfsstat – nfs server stats
– sar – kitchen sink utility
– vmstat – virtual memory stats

Wednesday, July 22, 2009

Application Status through WLST

Here is a way.

try:
cd('/ServerRuntimes/'+server_name+'/ApplicationRuntimes')
print '---------------------- Application status ---------------------'
apps = ls()
for appname in apps.split():
if appname != 'drw-':
cd('/ServerRuntimes/'+server_name+'/ApplicationRuntimes/'+appname)
if getMBean('ComponentRuntimes'):
# we may not have a component runtime, so check first
cd('/ServerRuntimes/'+server_name+'/ApplicationRuntimes/'+appname+'/ComponentRuntimes')
components=ls()
for component in components.split():
if not component.endswith('.jar'):
if component != 'drw-':
cd('/ServerRuntimes/'+server_name+'/ApplicationRuntimes/'+appname+'/ComponentRuntimes/'+component)
status=str(get('Name'))+': '
istate=cmo.getDeploymentState()
if istate == 0:
istate='UNPREPARED'
if istate == 1:
istate='PREPARED'
if istate == 2:
istate='ACTIVE'
if istate == 3:
istate='NEW'
print component + ' has status : ' + istate
except WLSTException,e:
# this typically means the server is not active, just ignore
print "This Server has no Application"

Tuesday, July 21, 2009

Monitoring Messaging Bridges

try:
    mBeans=home.getMBeansByType("MessagingBridgeRuntime")
    print '---------------------- Messaging Bridge ---------------------'
    print
    for bean in mBeans:
        if server_name != bean.getObjectName().getLocation():
            continue
        print bean.getName() + " is " + str(bean.getDescription()) + " and " + str(bean.getState())
except:
    print "This server has no Messaging Bridge"

Monitoring JDBC Connection pool using WLST : Betterway

try:
    mBeans=home.getMBeansByType("JDBCConnectionPoolRuntime")
    print '---------------------- JDBC Connection pool ---------------------'
    print
    for bean in mBeans:
        if server_name != bean.getObjectName().getLocation():
            continue
        print bean.getName() + " is " + str(bean.getState())
except:
    print "This server has no Messaging Bridge"

Thursday, July 16, 2009

JConsole JMX to Weblogic

Hello,

We found a workaround that doesn't need to compile and run a proxy.

Just set JAVA_HOME and BEA_HOME and run:

RedHat
jconsole -J-Djava.class.path=$JAVA_HOME/lib/jconsole.jar:/usr/bea40/wlserver_10.3/server/lib/wljmxclient.jar -J-Djmx.remote.protocol.provider.pkgs=weblogic.management.remote

Windows
jconsole -J-Djava.class.path=%JAVA_HOME%\lib\jconsole.jar;%BEA_HOME%\wlserver_10.3\server\lib\wljmxclient.jar -J-Djmx.remote.protocol.provider.pkgs=weblogic.management.remote


Connection string:
service:jmx:rmi:///jndi/iiop://localhost:7001/weblogic.management.mbeanservers.domainruntime



----------------------------------------


1. After having the same issue, it turned out that it is just a CLASSPATH issue when using jConsole from the latest SUN JVM:

a) Working for connect string starting with 'service:jmx:rmi:///jndi/iiop://...' only.
set JAVA_HOME=D:\SUN_jdk1.6.0_13
set PATH=%JAVA_HOME%\bin;%PATH%
jconsole -J-Djava.class.path=%JAVA_HOME%\lib\jconsole.jar;%bea_home%\wlserver_10.3\server\lib\wljmxclient.jar

b) Working for connect string starting with 'service:jmx:rmi:///jndi/iiop://...' and 'service:jmx:iiop:///jndi/iiop://...' .

set JAVA_HOME=D:\SUN_jdk1.6.0_13
set PATH=%JAVA_HOME%\bin;%PATH%
jconsole -J-Djava.class.path=%JAVA_HOME%\lib\jconsole.jar;%bea_home%\wlserver_10.3\server\lib\weblogic.jar

NOTE: The RMI or IIOP in the connect string!

c) I tried the following URLs that worked fine:

* service:jmx:rmi:///jndi/iiop://localhost:7001/weblogic.management.mbeanservers.runtime

* service:jmx:iiop:///jndi/iiop://localhost:7001/weblogic.management.mbeanservers.runtime

* service:jmx:rmi:///jndi/iiop://localhost:7001/weblogic.management.mbeanservers.domainruntime

* service:jmx:iiop:///jndi/iiop://localhost:7001/weblogic.management.mbeanservers.domainruntime

2. In addition, the parameter -J-Djmx.remote.proto.provider.pkgs=weblogic.management.remote can be set if the current version of the JVM has any issue:

jconsole -J-Djava.class.path=%JAVA_HOME%\lib\jconsole.jar;%bea_home%\wlserver_10.3\server\lib\wljmxclient.jar -J-Djmx.remote.proto.provider.pkgs=weblogic.management.remote

I hope this helps a bit!

Wednesday, July 15, 2009

Monitoring JDBC Connection pool using WLST

Here is a sample:


def jdbcConnectionPoolStatus(server_name):
    try:
        cd('/ServerRuntimes/'+server_name+'/JDBCConnectionPoolRuntime')
        print '---------------------- JDBC Connection pool ---------------------'
        jdbcPool = ls()
        for jdbcname in jdbcPool.split():
            if jdbcname != 'drw-':
                cd('/ServerRuntimes/Desktop_managedServer_1/JDBCConnectionPoolRuntime/'+jdbcname)
                print 'Connection pool ' + jdbcname + ' is ' + cmo.getState()
    except:
        print "This Server has no JDBC Connection Pool"

Good WLST resource

http://weblogicserver.blogspot.com/2009/02/do-not-step-on-others-feet-wlst.html

WLST Scripting: Know More on it: Eg.

### Script to create WebLogic Domain(s) from csv file
02.### Reusable Definitions
03.def buildDomain():
04. ### Read Basic Template
05. readTemplate(WL_HOME+"/common/templates/domains/wls.jar")
06. cd('Servers/AdminServer')
07. set('ListenAddress', adminServerAddress)
08. set('ListenPort', int(adminServerPort))
09. ### Create Admin User
10. cd('/')
11. cd('Security/base_domain/User')
12. delete('weblogic','User')
13. create(adminUser,'User')
14. cd(adminUser)
15. set('Password',adminPassword)
16. set('IsDefaultAdmin',1)
17. ### Write Domain
18. setOption('OverwriteDomain', 'true')
19. writeDomain(domainLocation+'/'+domainName)
20. closeTemplate()
21.def printConfirmation():
22. ### Print Confirmation
23. print ""
24. print "Created Domain With Following Values"
25. print "Domain Name = %s " % domainName
26. print "Domain Location = %s " % domainLocation
27. print "Admin User = %s " % adminUser
28. print "Admin Password = %s " % adminPassword
29. print "Admin Server Address = %s " % adminServerAddress
30. print "Admin Server port = %s " % adminServerPort
31.### Executable Script
32.### CreateDomain.py
33.import sys
34.### Define constants
35.WL_HOME = "/products/beaSB/wlserver_10.0"
36.### Read the command-line arguments
37.argslength = len(sys.argv)
38.if argslength < 2 :
39. print '==>Insufficient arguments'
40. print '==>Syntax: java weblogic.WLST CreateDomain.py csv.file'
41. exit()
42.else:
43. ### Read the csv file
44. fileName = sys.argv[1]
45. print('Reading File \"' + fileName + '\"' )
46. f = open(fileName)
47. try:
48. for line in f.readlines():
49. ### Strip the comment lines
50. if line.strip().startswith('#'):
51. continue
52. else:
53. ### Split the comma seperated values
54. items = line.split(',')
55. items = [item.strip() for item in items]
56. if len(items) != 6:
57. print "==>Bad line: %s" % line
58. print "==>Syntax: domainName, domainLocation, adminUser, adminPassword, adminServerAddress, adminServerPort"
59. else:
60. (domainName, domainLocation, adminUser, adminPassword, adminServerAddress, adminServerPort) = items
61.
62. ### Call the definition buildDomain
63. buildDomain()
64. ### Call the definition printConfirmation
65. printConfirmation()
66. except Exception, e:
67. print "==>Error Occured"
68. print e
69.exit()

Monday, July 13, 2009

Goo FAQ on Unix/Solaris

This is a good website

http://www.unixguide.net/sun/faq/

WLST Scripting: Know More on it

Here is a small script to get you started.

import java.lang.System as System
connect(userName,passWord,URL)
cd ('Servers')
servers = cmo.getServers()
cd('/')
runtime()

def isManagedServerRunning(server_name):
    cd('/ServerRuntimes/'+server_name+'/ServerLifeCycleRuntime/')
    print "Current state of server "+server_name+ " : " + cmo.getState()


def printHeapDetails(server_name):
    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'

def jdbcConnectionPoolStatus(server_name):
    cd('/')
    cd('/ServerRuntimes/Desktop_managedServer_1/JDBCConnectionPoolRuntime/DSSReportingPool')
    print "Current State of DSSReportingPool is : " + cmo.getState()


for myServers in servers:

    print "-----------------------------------"
    print 'Status of ' + myServers.getName()
    print "-----------------------------------"

    isManagedServerRunning(myServers.getName())
    printHeapDetails(myServers.getName())
    jdbcConnectionPoolStatus(myServers.getName())


exit()



More info on this can be availed at

1) http://weblogicserver.blogspot.com/search?updated-min=2009-01-01T00%3A00%3A00-08%3A00&updated-max=2010-01-01T00%3A00%3A00-08%3A00&max-results=5

2) http://weblogicserver.blogspot.com/2009/03/check-for-resourceconfiguration.html

Tuesday, July 07, 2009

List only directories

ls -F $1 | grep \/ | sed -e 's/\/$//g'

How do I save or redirect stdout and stderr into different files?

Q. I need to run a program called oraMon.pl. However this program is run from cron job. It report error to stderr and normal output to stdout. How do I save stdout, stderr and both into 3 separate log files?

A. It is not that hard if you know howto redirect stderr, stdout and a small command called tee.

=> fd0 is stdin
=> fd1 is stdout
=> fd2 is stderr

There are two formats for redirecting standard output and standard error:
&>word
and
>&word

For example anything written to fd2 to the same place as output to fd1, you will use:
2>&1

tee command read from standard input and write to standard output and file.

So to send stderr to /tmp/errors.log, stdout to /tmp/output.log and both to /tmp/final.log, type as follows:

((/path/to/oraMon.pl 2>&1 1>&3 | tee /tmp/errors.log) 3>&1 1>&2 | tee /tmp/output.log) > /tmp/final.log 2>&1

All about Unix Date command

Convert unix timestamp to date

# date -d @1221256800 "+%Y-%m-%d %T"
2008-09-13 00:00:00


Convert a date (YYYYMMDD) to unix timestamp

# date -d "20080913" +%s
1221256800

mtime ctime and atime

Unix keeps 3 timestamps for each file: mtime, ctime, and atime. Most people seem to understand atime (access time), it is when the file was last read. There does seem to be some confusion between mtime and ctime though. ctime is the inode change time while mtime is the file modification time. "Change" and "modification" are pretty much synonymous. There is no clue to be had by pondering those words. Instead you need to focus on what is being changed. mtime changes when you write to the file. It is the age of the data in the file. Whenever mtime changes, so does ctime. But ctime changes a few extra times. For example, it will change if you change the owner or the permissions on the file.

Let's look at a concrete example. We run a package called Samba that lets PC's access files. To change the Samba configuration, I just edit a file called smb.conf. (This changes mtime and ctime.) I don't need to take any other action to tell Samba that I changed that file. Every now and then Samba looks at the mtime on the file. If the mtime has changed, Samba rereads the file. Later that night our backup system runs. It uses ctime, which also changed so it backs up the file. But let's say that a couple of days later I notice that the permissions on smb.conf are 666. That's not good..anyone can edit the file. So I do a "chmod 644 smb.conf". This changes only ctime. Samba will not reread the file. But later that night, our backup program notices that ctime has changes, so it backs up the file. That way, if we lose the system and need to reload our backups, we get the new improved permission setting.

Here is a second example. Let's say that you have a data file called employees.txt which is a list of employees. And you have a program to print it out. The program not only prints the data, but it obtains the mtime and prints that too. Now someone has requested an employee list from the end of the year 2000 and you found a backup tape that has that file. Many restore programs will restore the mtime as well. When you run that program it will print an mtime from the end of the year 2000. But the ctime is today. So again, our backup program will see the file as needing to be backed up.

Suppose your restore program did not restore the mtime. You don't want your program to print today's date. Well no problem. mtime is under your control. You can set it to what ever you want. So just do:
$ touch -t 200012311800 employees.txt
This will set mtime back to the date you want and it sets ctime to now. You have complete control over mtime, but the system stays in control of ctime. So mtime is a little bit like the date on a letter while ctime is like the postmark on the envelope.

The find command uses arguments like:
-mtime -2
-mtime +2
-mtime 2

There are -ctime and -atime options as well. Since we now understand the differences among mtime, ctime, and atime, by understanding how find uses the -mtime option, the other two become understood as well. So I will describe find's use of the -mtime option.

As you probably know, the find command can run for minutes or hours depending on the size of the filesystem being searched. The find command makes a note of its own start time. It then looks at a file's mtime and computes how many seconds ago the file was modified. By dividing the seconds by 86,400 (and discarding any remainder), it can calculate the file's age in days:

Code:
0 days in seconds: 0 - 86399
1 day in seconds: 86400 - 172799
2 days in seconds: 172800 - 259159

So now that we know how many days ago a file was modified, we can use stuff like "-mtime 2" which specifies files that are 172800 to 259159 seconds older than the instant that the find command was started.

"-mtime -2" means files that are less than 2 days old, such as a file that is 0 or 1 days old.

"-mtime +2" means files that are more than 2 days old... {3, 4, 5, ...}

It may seem odd, but +0 is supposed to work and would mean files more than 0 days old. It is very important to recognize that find's concept of a "day" has nothing to do with midnight.

Rename extension of all files in a folder

Here is a way to do this from command line

ls *.sh | sed 's/\(.*\)\.sh/ & \1.pl/' | xargs -L1 mv


Ok there are four commands here all piped.

ls
sed
xargs
mv

I used ls to filter all .sh files.

I used sed to substitute all .sh to .pl. What it does is creates argument for mv command. Test it with ls *.pl | sed 's/\(.*\)\.pl/ & \1.sh/'

I used xargs with mv to move sh to pl. the –L switch is used to get input form sed pipe