uderstanding .ksh -part 2

hi guys

This question is in continuation to my earlier question(http://www.experts-exchange.com/OS/Linux/Q_28253505.html#a39536410)
We inherited some .ksh from another team which we are trying to understand.

My questions are in comments..

pushd . > /dev/null              #what does pushd . > mean
cd `dirname ${SCRIPT_PATH}` > /dev/null    # cd is change directory but little confused what the entire line means
SCRIPT_PATH=`pwd`                          # $pwd shows the present working directory, what does 'pwd' mean
CO_HOME=`dirname $SCRIPT_PATH`;      
popd  > /dev/null                         #what does popd mean?

# specify the JVM heap size
MEMORY=512m 
. $CO_HOME/properties/app.cf

echo $JAVA_HOME
if [ -f $JAVA_HOME/bin/java ]; then      #what does -f mean
  JAVAEXEC=$JAVA_HOME/bin/java
else
  JAVAEXEC=java
fi

if [[ $1 == '-jmx' ]]; then
    JMXPROPERTIES="-Dtangosol.coherence.management=all -Dtangosol.coherence.management.remote=true"
    shift     #what does shift command mean?
fi

CONFIG_FILE=$1    # $1 is the first parameter
echo $CONFIG_FILE 
JAVA_OPTS="-Xms$MEMORY -Xmx1g -XX:+UseParallelOldGC $JMXPROPERTIES"

echo "Sleeping for 10 secs"
sleep 10

TODAY=$(date '+%Y%m%d%S')
LOGFILE=${CO_HOME}/log/stdout.DefaultCacheServer.$CONFIG_FILE.$TODAY  #construct the LOGFILE

$JAVAEXEC -server -showversion $JAVA_OPTS  -Dtangosol.coherence.cacheconfig=${CONFIG_FILE} -cp "$CO_HOME/lib/coherence.jar:$CO_HOME/properties" com.tangosol.net.DefaultCacheServer $1 > $LOGFILE  2>&1 &    #What is this entire statement doing?

CHILD_PID=$!   # what does $! mean ?
PID_FILE=${CO_HOME}/runprops/PROJECT.PIDS.DEFAULTCACHESERVER.${CONFIG_FILE}   #construct a PID File
echo "${CHILD_PID}" > ${PID_FILE}   # what does > mean in this echo statement?

RET_VALUE=$?      # what does $? mean 
echo "RC : $RET_VALUE"

Open in new window


Any help will be really appreciated.
thanks.
royjaydAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gerwin Jansen, EE MVETopic Advisor Commented:
Here are a few:

$? - return code of previously executed command
$! - child process id
>  - redirect output
shift - 'shift' parameters one position to the left, use first parameter, shift and use first parameter again (until no more are there)
-f - check whether a file exists
popd / pusd - pusd currect directory on the stack, popd - get last entry from stack
0
Gerwin Jansen, EE MVETopic Advisor Commented:
pwd - print working directory - `pwd` executes pwd in a subshell, used to assign the output to a variable for instance
cd `dirname ${SCRIPT_PATH}` > /dev/null - first executes dirname to get the directory part of what is in ${SCRIPT_PATH} (in a sub shell) - then cd (changes directory) to the output of that
line 33 - basically starts a java (server) application with a few parameters, sends output to a logfile, redirect output and in the background (& at the end)
0
TintinCommented:
Line 1 - Pushes the current directory (.) onto the stack.  The >/dev/null gets rid of any output

Line 2 -  cd's to the first path in the variable $SCRIPT_PATH.   For example, if 4SCRIPT_PATH was set to /usr/local/bin, then then dirname would return /usr

Note that SCRIPT_PATH must be set elsewhere, otherwise this line makes no sense.

Line 5 - Pops the last directory "pushed" to the stack and discards any output.  

Line 12 - The -f tests if the specified file exists

Line 20 - shift is used to shift the specified parameters.   For example, if I call a script with

./script ABC XZY

Then $1 contains 'ABC' and $2 contains 'XZY'.

If I do

shift

$1 now contains 'XZY' and $2 contains nothing

If I do

shift 2

It shifts both parameters, effectively leaving no parameters.

In your specific script, it can be optionally called with the -jmx flag along with the config file.   By testing if -jmx is the first parameter, the parameters are then shifted so that the config file is always $1

Line 33 - This is starting java with a whole bunch of parameters.

The part:

>$LOGFILE 2>&1

Means send all output (stdout and stderr) to $LOGFILE.   The 2>&1 part of it means redirect stderr to stdout.   This is a very common syntax to capture all output.

The & at the end of the line means run it in the background.

Line 35 - $! is a special built in variable that contains the process ID (PID) of the last command run in the background (in this case, the java process)

Line 37 - echo the value of $CHILD_PID into the file with the path set in $PID

Line 39 - $? is a special built in variable that contains the exit status of the last command.   In almost all cases, 0 means success and non-zero means failure.   In this case it would be non-zero if the echo command on line 37 failed for whatever reason, eg: permissions.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
royjaydAuthor Commented:
thanks very much guys, i will get back with some questions if i have.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.