Ahoy there! This is my personal blog which I use as my memory extension and a medium to share stuff that could be useful to others.

I just watched LIVE, the 12-round demolition of Miguel Cotto by Manny Pacquiao earning Manny the WBO welterweight title. Manny created history by winning a seventh world title in an unprecedented seventh weight division.

Manny Pacquiao (left) and Miguel Cotto

 

Manny was simply superb – very lively, darting in and out, punched with lightning speed and accuracy and although he stepped up in weight, it did not show one bit. Cotto landed a few good punches, but Manny seemed unperturbed by them. Manny had Cotto down a couple of times before the referee stopped the fight in the last round. Manny dominated the fight and proved that welterweight power ain’t a problem for him and his iron chin, by demolishing a great welterweight champion.

Now, the fight every boxing fan will want to see is Manny Pacquiao Vs Floyd Mayweather Jr. Both these boxers are the top two contenders for the planet’s best pound-for-pound boxers and exhibit excellent boxing skills and speed. A fight between them is a mouth-watering prospect!

VN:F [1.6.5_908]
Rating: 0 (from 0 votes)

UNIX shell commands return exit statuses or exit codes upon completion, irrespective of whether successful or not. In UNIX, an exit status of 0 indicates successful execution of a command and a non-zero exit status indicates a failure. Some shells (e.g. ksh93) document the various exit statuses and their meanings. So, checking exit statuses of commands is typically done in programs like shell scripts to decide further action to be taken by the script.

However, piped commands or a pipeline (cmd A | cmd B), add a twist to checking exit statuses as by default, most UNIX shells adhere to the POSIX requirement of returning the exit status of the last command in the pipe. Refer the example below:

 

#
# Two commands piped and both commands are successful.
#
$ grep MemTotal /proc/meminfo | awk '{print $2}'; echo "EXIT STATUS = $?"                                                                      
1056836
EXIT STATUS = 0
#
# Two commands piped and first command throws an error.
# Note that the EXIT STATUS is still 0
#
$ grep MemTotal /proc/meminf | awk '{print $2}'; echo "EXIT STATUS = $?"
grep: /proc/meminf: No such file or directory
EXIT STATUS = 0

 

So, checking the exit status of a pipeline as in the above example will cause problems for your script if any of the piped commands other than the last command throw an error. Given below are two solutions (using ksh93 and bash) to solve this problem and ensure a valid exit status check for a pipeline:

SOLUTION 1: Using ksh93 and the pipefail option

The Korn Shell 1993 version ‘g’ point release (ksh93g) introduced a pipefail option which ensures that the exit status of a pipeline will be that of the first command in the pipe that has failed (of course, the exit status of the pipeline will be 0 if all commands in the pipe succeed). Unfortunately, ksh88 is distributed as the default Korn Shell with most UNIX systems (with all Solaris versions I believe) because ksh93 is owned by Lucent and AT&T and there were licensing restrictions. Refer I (Q.14) and III (Q.8) of the Korn shell FAQs at http://kornshell.com/doc/faq.html

An example of how the pipefail option is used is shown below:

 

#
# Check ksh version
#
$ ksh --version
  version         sh (AT&T Research) 93s+ 2008-01-31
#
# Set pipefail option on (it's off by default)
#
$ set -o pipefail
#
# Now, notice the non-zero exit status due to the error in the first command
#
$ grep MemTotal /proc/meminf | awk '{print $2}'; echo "EXIT STATUS = $?"
grep: /proc/meminf: No such file or directory
EXIT STATUS = 2

 

Note: There are other solutions using ksh88 with co-processes and file descriptor manipulation, but those solutions are not script-friendly.

 

SOLUTION 2: Using bash and the PIPESTATUS array

The bash shell uses an array called PIPESTATUS to store the exit statuses of commands in a pipeline.

 

#
# Using the PIPESTATUS array to display exit statuses of both commands in the pipe
#
mrkips@mrkips-laptop:~$ grep MemTotal /proc/meminf | awk '{print $2}'; echo "EXIT STATUS = ${PIPESTATUS[0]}"
 
grep: /proc/meminf: No such file or directory
 
EXIT STATUS = 2
 
 
mrkips@mrkips-laptop:~$ grep MemTotal /proc/meminf | awk '{print $2}'; echo "EXIT STATUS = ${PIPESTATUS[1]}"
 
grep: /proc/meminf: No such file or directory
 
EXIT STATUS = 0

 

Be aware of SIGPIPE

SIGPIPE is a signal sent to a process (that causes the process to terminate) that writes to a pipe when there is nothing to read from the pipe. If you use any of the above mthods to check the exit status of a pipeline and a SIGPIPE is received by one of the commands in the pipeline, then your exit status may not correlate with the success/failure of the pipeline.

For example, in the command,

ls -lrt | head -1

“ls -lrt” writes to a pipe and “head -1″ reads from that pipe. Now, “head -1″ only requires the first line from the pipe and as soon as it gets it, it terminates and sends a SIGPIPE (signal 13) to “ls -lrt” causing “ls -lrt” to terminate with a non-zero exit code.

 

NOTE:

(1) The how-to above describes how I implemented something and may not be the only method of implementation.

(2) Your rating of this post will be much appreciated. Also, feel free to leave comments.

VN:F [1.6.5_908]
Rating: +9 (from 9 votes)

Problem:

WebLogic10_ActivateChanges

 

When activating changes (clicking the button "Activate Changes" as shown in the image on the left) on the Administration console of a WebLogic 10.0 MP1 domain comprising an admin server and two managed servers (each managed server on a different host), it took around 5 minutes for the activation to complete.

 

 

 

 

Background:

From WebLogic Server versions 9.x and later, any changes performed on the Administration console must go through a three-step process – (1) Lock and Edit (2) Edit config (3) Activate Changes. It’s the third step in this process that took about 5 minutes to complete. The changes were successfully made, albeit after 5 minutes. Interestingly, when we located all the managed servers in the domain on the same host, this problem disappeared and the activation of changes took less than 10 seconds. However, locating all managed servers on one host cannot be a solution. We enabled debug for Deployment on all servers. Given below is the output of the debug during occurrence of the problem:

 

####<Sep 29, 2009 10:56:45 AM BST> <Debug> <Deployment> <myhost> <myadmin> <[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1254218205661> <BEA-000000> <Experienced Exception while c.tryLock() and it is ignored :: java.nio.channels.OverlappingFileLockException
at sun.nio.ch.FileChannelImpl.checkList(FileChannelImpl.java:853)
at sun.nio.ch.FileChannelImpl.tryLock(FileChannelImpl.java:820)
at java.nio.channels.FileChannel.tryLock(FileChannel.java:967)
at weblogic.deploy.internal.targetserver.datamanagement.ConfigDataUpdate.getFileLock(ConfigDataUpdate.java:374)
at weblogic.deploy.internal.targetserver.datamanagement.ConfigDataUpdate.getFileLock(ConfigDataUpdate.java:357)
at weblogic.deploy.internal.targetserver.datamanagement.ConfigDataUpdate.acquireFileLock(ConfigDataUpdate.java:338)
.
.
.

 

Solution:

After liasing with Oracle Support, we upgraded our JVM and the upgrade resolved the problem. After the upgrade, the activation of changes took less than 10 seconds irrespective of whether the managed servers were located on the same host or not. Details of the upgrade are given below:

Old JVM:

java version “1.5.0_14″
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_14-b03)
BEA JRockit(R) (build R27.5.0-110_o-99226-1.5.0_14-20080528-1505-linux-x86_64, compiled mode)

 

New JVM:
java version “1.5.0_17″
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_17-b04)
BEA JRockit(R) (build R27.6.3-40_BR8141840-120019-1.5.0_17-20090828-1133-linux-x86_64, compiled mode)

 

Root Cause:

Bug in JVM 1.5.0_14 (JRockit R27.5.0)

 

NOTE:

(1) The solution above describes a successful problem-solving experience and may not be applicable to all problems with similar symptoms.

(2) Your rating of this post will be much appreciated. Also, feel free to leave comments.

VN:F [1.6.5_908]
Rating: +3 (from 3 votes)

At times, you may want to determine the elapsed wall-clock time or uptime for a running process. While you can determine the process’ elapsed time using certain versions of the ps utility, it can also be determined using a simple shell script with a bit of perl. Both these methods are described below with the init process (PID = 1):

SOLUTION 1: The ps utility on some variants of UNIX (e.g. Linux, but not Solaris)

ps -oetime 1
    ELAPSED
      39:45

 

SOLUTION 2: A shell script with a bit of perl (should work on all variants of UNIX)

Download the shell script (puptime.ksh) or copy and paste from below:

#!/bin/ksh
# puptime.ksh - Gavin Satur - http://cybergav.in/2009/11/09/puptime
# Simple script to calculate the uptime (elapsed wall clock time) of a process
##############################################################################
#
# Accept PID and do some basic validation
#
proc_pid=$1
if [ -z "$proc_pid" ]; then
   print "\nERROR : Missing input argument. SYNTAX: ksh puptime.ksh <pid>\n"
   exit 999
fi
if [ ! -d /proc/$proc_pid ]; then
   print "\nERROR : No directory for PID $proc_pid in /proc. Check if process is running!\n"
   exit 999
fi
#
# Calculate start time of process and current time in epoch time using a bit of perl
#
proc_stime=`perl -e 'use File::stat;  my $filename = "$ARGV[0]"; $sb = stat($filename); printf "%s", $sb->mtime;' /proc/$proc_pid`
currtime=`perl -e 'print time;'`
#
# Calculate process uptime in seconds and then slice'n'dice for human-friendly output
#
proc_time=$(( currtime - proc_stime ))
proc_time_days=$(( proc_time / 86400 ))
proc_time_secs=$(( proc_time % 86400 ))
proc_time_hours=$(( proc_time_secs / 3600 ))
proc_time_secs=$(( proc_time_secs % 3600 ))
proc_time_minutes=$((proc_time_secs / 60 ))
proc_time_secs=$(( proc_time_secs % 60 ))
print "\nUPTIME FOR PROCESS WITH PID $proc_pid = $proc_time_days day(s) $proc_time_hours hour(s) $proc_time_minutes minute(s) $proc_time_secs second(s) \n"
./puptime.ksh 1
UPTIME FOR PROCESS WITH PID 1 = 0 day(s) 0 hour(s) 39 minute(s) 37 second(s)
VN:F [1.6.5_908]
Rating: +2 (from 2 votes)

I watched the David Haye Vs Nikolai Valuev WBA Heavyweight title fight a couple of hours ago. There was a lot of hype before the fight billed as “David Vs Goliath”, given the whopping 7 stone weight difference and significant height difference between the two boxers. Before the fight, David promised that he would be the first man to knock out the “beast from the east” and did some thrash talking about the huge Russian.

Nikolai-Valuev-v-David

 

Well, the fight was far from a spectacle, it was twelve rounds of a cat-and-mouse game, not many punches exchanged and there was no knock out. David Haye won by a majority decision on points and is now the WBA Heavyweight Champion of the world. David was slipping and sliding more than punching. His negative tactics were understandable since he was facing a giant with a massive height and weight advantage, but he could have thrown more punches in the earlier rounds as he in fact rocked Nikolai a bit in the last round with a combination (after the match, David said that he hurt his right hand in the early rounds and so didn’t use it much).

Although no boxing fan would want to see a title being won in such a boring match (and some may even argue that David did not do much in the fight to win the title) , David’s victory is a breath of fresh air for the boxing Heavyweight division. David Haye has the skill, speed, power, aggression and charisma for a world champion (though he can do without a bit of the thrash talking pre-fight), whereas Nikolai is just a boring giant who relies more on his size than skill. Lot of big bucks await David Haye and I wish him well. It will be interesting to watch him take on the Klitshcko brothers.

VN:F [1.6.5_908]
Rating: 0 (from 0 votes)

 Page 11 of 27  « First  ... « 9  10  11  12  13 » ...  Last »