1833401 Members
3611 Online
110052 Solutions
New Discussion

Re: Script

 
Hunki
Super Advisor

Script

I was making a Shutdown/Startup script for JBOSS on solaris and while having it run as root I was getting an error of "is not an Identifier" while exporting stuff like JAVA_HOME; JBOSS_HOME. Once I removed them and put in the complete path instead of a relative one then everything worked fine

But my question is how can i export JAVA_HOME ; JBOSS_HOME in my script.
15 REPLIES 15
Sandman!
Honored Contributor

Re: Script

Put the line "set -a", on a line by itself, near the top of your script before any variable definition or precede every variable name with the keyword "export" like

export JAVA_HOME=/path_to/java/binaries
Peter Nikitka
Honored Contributor

Re: Script

Hi,

the SOlaris executable /usr/bin/sh is NOT the posix compliant shell - it is really the old Bourne Shell. So this syntax is invalid there:
export VAR=value

You have to use
VAR=value; export VAR
instead.

Using ksh or bash as interpreter will make the first construct valid.

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Hunki
Super Advisor

Re: Script

I tried it with ksh but the i was getting the same error. ( "is not an Identifier" ).How will it work with ksh.

hunki
Peter Nikitka
Honored Contributor

Re: Script

Hi,

check first the call of the correct interpreting shell in the first line of your script. It should be
#!/usr/bin/ksh

Please send an example of the failing assignment to a variable as well!

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Hunki
Super Advisor

Re: Script

I am using :

#!/bin/ksh

do I need to change it to :

#!/usr/bin/ksh

thanks,
hunki
Hunki
Super Advisor

Re: Script

export JAVA_HOME=/usr/bin/java ...
Peter Nikitka
Honored Contributor

Re: Script

Hi,

you need not change this - Solaris has a compatibility link /bin -> /usr/bin
like HP-UX.

The solution is to change
export VAR=value
to
VAR=value; export VAR

Solaris will call your script at startup NOT via the interpreter in your file but with a hardcoded one NOT being able to parse your original statement.

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Sandman!
Honored Contributor

Re: Script

Can you attach your script so that it can be looked at?
Hunki
Super Advisor

Re: Script

Okie here is the script ... the requirement has changed a little .

I use this script as :

jboss start
jboss stop

and I have 2 instances of jboss running here :

default & default2

I want the the script be modified so that I can specify individual instances of JBOSS and start or stop them like this :

jb start default
jb stop default

OR

jb start default2
jb stop default2

( default and default2 are mentioned in the script )

Can the script be modified to reflect this requirement while also keeping the startup /stop option open since its startup script. ( I mean $2 ( default etc ) shud be optional and shud not hamper while the jboss is restarted by the system after the reboot )

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

#!/bin/ksh
# File: jboss4.04.server
#
# Purpose: Start/Stop JBoss Application Server
#
# Parameter: start|stop|check
#
#
# Changes:
#

usage() {
echo "Usage: jboss start|stop" 1>&2
exit 1
}

#############main############

[ $# -ne 1 ] && usage

fct=$1

check_running(){
if [ `ps -u gtaq | grep java | grep -v grep | wc -l` -ne 0 ]; then
return 0
else
return 1
fi
}

### main ###
case "$fct" in
start)
check_running && echo "JBoss already running!" && exit 1
echo "Starting JBoss..."
su - gtaq -c "nohup /export/home/jack/jboss-4.0.4.GA/bin/run.sh -c default >/dev/null 2>/dev/null &"
su - gtaq -c "nohup /export/home/jack/jboss-4.0.4.GA/bin/run.sh -c default2_test >/dev/null 2>/dev/null &"
echo "Server startup may take a while - "
echo "check logfile /export/home/jack/jboss-4.0.4.GA/server/default/log/server.log for completion"
echo "check logfile /export/home/jack/jboss-4.0.4.GA/server/default2/log/server.log for completion"
;;
stop)
su - gtaq -c "/export/home/jack/jboss-4.0.4.GA/bin/shutdown.sh -S default"
su - gtaq -c "/export/home/jack/jboss-4.0.4.GA/bin/shutdown.sh -S -s jnp://localhost:1201"
;;
esac

Sandman!
Honored Contributor

Re: Script

>I want the the script be modified so that I can specify individual instances of >JBOSS and start or stop them like this :

>jb start default
>jb stop default

>OR

>jb start default2
>jb stop default2


Yes you can stop individual instances of the server by using a nested case statement for example:

case "$fct" in
start)
case $2 in
default)
echo "starting default jboss server"
;;
default2)
echo "starting default2 jboss server"
;;
"")
echo "starting all jboss servers..."
;;
*)
echo "invalid parameter...exiting"
exit
;;
esac
;;
stop)
case $2 in
default)
echo "stopping default jboss server"
;;
default2)
echo "stopping default2 jboss server"
;;
"")
echo "stopping all jboss servers..."
;;
*)
echo "invalid parameter...exiting"
exit
;;
esac
;;
esac
Hunki
Super Advisor

Re: Script

Thanks for replying Sandman !

One more thing by putting in the nested case statements do I hamper the system's ability to start and stop jboss while a rebooting or shutting down the system because for the system there is not $2 here.
The $2 is for us while restarting JBOSS on the command line. Please correct me if I am wrong.

Thanks,
hunki
Sandman!
Honored Contributor

Re: Script

>One more thing by putting in the nested case statements do I hamper the >system's ability to start and stop jboss while a rebooting or shutting down the >system because for the system there is not $2 here.
>The $2 is for us while restarting JBOSS on the command line. Please correct >me if I am wrong.


It will be okay during a reboot since the code below relies on $2 being empty:

"")
echo "starting all jboss servers..."

The above code is nested within the start and stop cases. So when the run-level scripts are being executed and there is no $2 parameter on the command line, it will enter the case mentioned above and either start or stop all the jboss servers (assuming you have a start all or stop all jboss servers script).

~cheers
Sandman!
Honored Contributor

Re: Script

You need to tweak the code below otherwise it will error out if you need to start or stop a particular instance of the jboss server.

> [ $# -ne 1 ] && usage

The above statement will cause commands like:

# jboss stop default
Or
# jboss start default

to error out

~hope it helps
Hunki
Super Advisor

Re: Script

Thanks Sandman , One more question...

I have two boxes on which I need to have this script and I want the same script to work on both boxes , how to achieve this within the case statement u earlier descirbed. Can u pls send me a layout of the case statements with the box names in it.

Thanks
hunki
Hunki
Super Advisor

Re: Script

I found the way to nest the cases for each boxes.