Shell Script : Difference between $* and $@

$*   – All command line parameters

$@  – All command line parameters

“$*” – takes the entire list as one argument

“$@” – takes the entire list and seperates into seperate arguments

bash-3.00$ less test.sh
#!/usr/bin/sh

for str in “$*”
do
echo $str
done

bash-3.00$ ./test.sh a b c
a b c

bash-3.00$ less test.sh
#!/usr/bin/sh

for str in $*
do
echo $str
done

bash-3.00$ ./test.sh a b c
a
b
c

Comments (1)

Spring Tip: Log4j configuration

Place log4j.properties in WEB-INF directory of the web application,

log4j.rootLogger=INFO, stdout, fileAppender

# Used only for development.
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} [%t] %-5p (%F:%L) – %m%n
log4j.logger.net.sf.ehcache=TRACE

# File appender used in production.
log4j.appender.fileAppender=org.apache.log4j.RollingFileAppender
log4j.appender.fileAppender.File=${app.logdir}/app.log

log4j.appender.fileAppender.MaxFileSize=1MB
log4j.appender.fileAppender.MaxBackupIndex=5

log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.fileAppender.layout.ConversionPattern=%d{ISO8601} %t %p %c – %m%n

In web.xml add


<context-param>
	<param-name>log4jConfigLocation</param-name>
	<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>

<context-param>
	<param-name>log4jRefreshInterval</param-name>
	<param-value>1000</param-value>
</context-param>

<listener>
	<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

Comments (3)

Spring Tip : how to reference local xsd file.

Got this exception when I changed the spring configuration file from using dtd to xsd,

SRVE0100E: Did not realize  init() exception thrown by servlet dispatcher: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 4 in XML document from ServletContext resource [/WEB-INF/dispatcher-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element ‘beans’.
Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element ‘beans’.
Had to google around for some time to find a solution. The original solution is written here.

This works!. Just elaborating what i did on Websphere 6.1 server to solve this…

Extract the spring.jar file to a temp directory and take the META-INF directory from it.

Delete the existing MANIFEST.MF file and created a new jar “spring-schemas.jar” with just the META-INF directory as content.

Now, On Websphere admin console.. goto..

Environments > Shared Libraries

and create a new one named SPRING_SCHEMA pointing to spring-schemas.jar.

Now add this library to the server at

Application servers > server1 > Class loader > Classloader_1203675889577 > Library Reference

That’s it. Restart the server and the error should be gone.

Comments (2)

Clearcase Tip : unreserved checkout

This simple tip is for those who are using clearcase command line interface for work.

In clearcase command line to checkout a file or directory, we type

>cleartool co <file/dir name>

Unfortunately the default checkout option in clearcase is reserved. How to change this default setting to unreserved?

1. create a .clearcase_profile file in your home directory and enter this line,

checkout -unreserved

2. In .bashrc

export CLEARCASE_PROFILE=~/.clearcase_profile

Learned from here.

Leave a Comment

Unix Tip: find command

Every one knows that find is an indispensable tool when you are working on Unix.  But how many of you know about the -follow flag?

I was using it for years and till yesterday i haven’t come across an issue with the command.

Yesterday evening i was trying to locate an *.so file and noticed this interesting behaviour.

bash-3.00# pwd
/apps/jsws/webservers/https-ws.advisorchannel.com-444/components/fmr-plugins
bash-3.00# find ./ -name ‘*.so’ | wc -l
78
bash-3.00# cd ..
bash-3.00# find ./ -name ‘*.so’ | wc -l
0

When i do a find from one location, it says.. there are 78 files. When i just move back and run the find command again… it gives zero. Strange…!!! rite?

It took some time for me to figure out why this strange behavior was occurring.

I was about to send out an email  telling that ‘.so’ files are missing.. then i noticed this,

bash-3.00# ls -l
total 2
lrwxrwxrwx   1 httpdadm httpdadm      26 Jul  8 10:01 fmr-plugins -> /apps/fmr-plugins/TKP15S02
lrwxrwxrwx   1 httpdadm httpdadm      31 Jul  8 10:01 jsws -> /apps/jsws/httpd/JSWS-7.0.1_S15

Ok, so that is the reason.  Two of the sub directories under “components” are symlinks.

Find command, by default, does not recursively traverse symlinks. You need to add -follow flag.

bash-3.00#find ./ -name ‘*.so’ -follow | wc -l
273

Comments (2)

Solaris : How to find files opened by a program

Get the pid of the program

$ps -ef | grep “program name”

$pfiles <pid>

This will
list all the files and sockets used by the program.

Leave a Comment

Three must have Aliases in Unix

These three are the must have aliases in your .bashrc file,

#alias rm=’rm -i’ — not useful while deleting directories. It will repetadly prompt for each file.

alias rm=’~/scripts/safe_rm.sh’
alias cp=’cp -i’
alias mv=’mv -i’

safe_rm.sh looks like this,

#!/usr/bin/ksh
YES=yes
CHOICE=no
FILE=$1
FORCE=”

if [[ $1 = '-rf' ]]; then
FILE=$2
FORCE=$1
fi

#if [[ -d $FILE && ! -e $FORCE ]]; then
# FORCE=’-rf’
#fi

echo “rm: remove $FILE (yes/no)?”
read CHOICE

if [[ $CHOICE = $YES ]]; then
echo “rm $FORCE $FILE”
rm $FORCE $FILE
fi

I was late in setting them and had to pay the price today.

Set them before you do an accidental delete or overwrite of important files.

Leave a Comment

Clearcase Tip : command line merge

Scenario – I did an unreserved checkout of a parent directory which is used by many people and added a new directory + files inside it. Now i need to checkin my changes.

first do -> ct lsco -d . from the parent directory.

eg:-

bash-3.00:/view/<view_name>/v_webservers$ct lshistory -d .

From the output of this command you can get the latest version of the parent directory.

Now, run merge command to merge in the changes.

bash-3.00:/view/<view_name>$ct merge -to v_webservers -version /main/ibg_webservers_7.0.0_bos/26

Leave a Comment

Clearcase Command Line Links

Clear Case command line client reference.

Config Spec explained.

Know more about  clearcase merging.

Leave a Comment

Solaris: how to start ftp service?

To enable ftp use inetadm -e ftp

to disable it use inetadm -d ftp

Leave a Comment

« Newer Posts · Older Posts »