0

Could someone please tell me what does the below code implies ?

NAME=`basename $0`
unset ISBOOT
if [ ${NAME:0:1} = "S" -o ${NAME:0:1} = "K" ]
then
        NAME=${NAME:3}
        ISBOOT=1
fi

This is inside the tomcat start up script & what these lines exact means to ?

0

If the filename (without any path) of the running script ($NAME) begins with an "S" or a "K" then:

  • chop off the first three characters of $NAME
  • set $ISBOOT to equal 1

What that actually means is anyone's guess. You'd have to examine the script itself to find out what it does with those variables.

I'd guess that the "S" and "K" are significant because the script is probably an init.d script under /etc/rc?.d/ - these scripts use symlinked names starting with "S" to be run when the run-level is starting (e.g. bootup) and "K" for scripts to start when the run-level is ending (e.g. shutdown). S=Start, K=Kill.

It chops off the first three characters of the filename because the symlinks are typically named like "S05scriptname" and "K10scriptname", where the number indicates the order that the script is to be executed. so "S01foo" runs before "S99bar"

So, the point of all that is to get the name of the script without that sysv rc-script naming stuff.

Probably because it's a script that does different things depending on what name it is invoked with.

Again, you'd have to examine the script to find out what it does depending on its name and whether ISBOOT==1 or not.

0

This script can be copied to /etc/init.d and then soft linked in one of subfolderts of /etc/rc.d directory. It usually is linked twice - once with "S" as a first letter of link name end second with "K" as a first letter. Links which names starts with S are executed during boot and those with K during the shutdown. The 2-digit numbers after first letter will decide about order of executing all booting or all shutdown scripts. It is common that both S-links and K-links are linking to the same script. The part of script you are asking for is basically checking if it is run as a booting or shutdown time script - it can be also run interactively, so it can act accordingly.

 NAME=`basename $0`

This line takes the name of script (or link in this case) and write it to NAME variable.

unset ISBOOT

This line unsets any value of ISBOOT variable.

 if [ ${NAME:0:1} = "S" -o ${NAME:0:1} = "K" ]

This line checks if first letter of value in NAME variable is S or K.

 then
    NAME=${NAME:3}
    ISBOOT=1 
 fi

If this is true it cuts off first 3 letter of name (S or K letter and 2-digit number) and sets ISBOOT variable to value of "1".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.