Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 704
  • Last Modified:

Startup shell script

Hi Experts
I need to write a .sh script that would execute the following 3 scripts sequentially on solaris, in the order mentioned below:
1. startAdminServer.sh
2.startEjbServer.sh
3.startPortalServer.sh

 The catch is that if i run each of the they startup a particular server. Only after it has started the server, I should execute the next script. I come to know the server is completely started when it shows me the server is in RUNNING mode after i have executed a .sh file. It takes min 20 sec's to max 1 minute for a server to be cometely started.

 I would like to write a shell script(.sh) to be executed on solaris, to do the above mentioned.

 Any help would be appreciated.
Prashant

0
prashant_khanna
Asked:
prashant_khanna
  • 9
  • 5
2 Solutions
 
jgiordanoCommented:
This is the quickest way to get it going; BUT The correct way would be to check if the process exists before starting the next one.
#!/usr/bin/ksh


<PUT THE PATH HERE>/startAdminServer.sh
sleep 120 #This will wait 2 minutes before starting next one
<PUT THE PATH HERE>/startEjbServer.sh
sleep 120 #This will wait 2 minutes before starting next one
<PUT THE PATH HERE>/startPortalServer.sh
0
 
prashant_khannaAuthor Commented:
How do i do that ?
0
 
jgiordanoCommented:
Give me 5 minutes and I will write it; I am in the middle of something else
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
prashant_khannaAuthor Commented:
Alright, would be waiting for your reply.

Thanx


0
 
jgiordanoCommented:
quick question how do you start these regular? do you add any parameters? or do you just execute startAdminServer.sh
0
 
prashant_khannaAuthor Commented:
just execute them

for example to execute startAdminServer.sh i  go to the appropriate directory at which the .sh is located and do

 > ./startAdminServer.sh

0
 
jgiordanoCommented:
Does it take a few seconds to come back to the command prompt?

if so you can use the syntax above because it will execute the same way as you do execute one wait until it comes back then do the next.
0
 
jgiordanoCommented:
also what do you execute to validate that the server is RUNNING
0
 
prashant_khannaAuthor Commented:
I see something like this on the screen:

<Oct 8, 2004 4:06:31 PM EDT> <Warning> <Management> <BEA-141120> <Unable to reconnect to the managed server ejbServer with the reconnect URL t3://148.98.150.47:2021.>
<Oct 8, 2004 4:06:31 PM EDT> <Notice> <WebLogicServer> <BEA-000329> <Started WebLogic Admin Server "adminServer" for domain "sbm5" running in Production Mode>
<Oct 8, 2004 4:06:31 PM EDT> <Notice> <WebLogicServer> <BEA-000360> <Server started in RUNNING mode>
0
 
jgiordanoCommented:
#!/usr/bin/ksh

job=<NAME FOR THIS JOB i.e. "server_start">

LOGFILE=<LOCATION FOR LOGFILE>/${job}.log

# redirect output and error to the log file
exec 1>${LOGFILE}
exec 2>>${LOGFILE}



print +++++++++++++++++++++++++++++++++++++++++++++++++ > $log 2>&1
print Starting  startAdminServer.sh `date`          >> $log 2>&1
print +++++++++++++++++++++++++++++++++++++++++++++++++ >> $log 2>&1

./startAdminServer.sh

print +++++++++++++++++++++++++++++++++++++++++++++++++ > $log 2>&1
print Starting  startEjbServer.sh `date`          >> $log 2>&1
print +++++++++++++++++++++++++++++++++++++++++++++++++ >> $log 2>&1
./startEjbServer.sh


print +++++++++++++++++++++++++++++++++++++++++++++++++ > $log 2>&1
print Starting  startPortalServer.sh `date`          >> $log 2>&1
print +++++++++++++++++++++++++++++++++++++++++++++++++ >> $log 2>&1

./startPortalServer.sh



print +++++++++++++++++++++++++++++++++++++++++++++++++ > $log 2>&1
print Completed `date`          >> $log 2>&1
print +++++++++++++++++++++++++++++++++++++++++++++++++ >> $log 2>&1


0
 
jgiordanoCommented:
All of the output would go to the log file defined and the next process would not start until the previous one finished; I would just put a sleep <SECONDS> in after each command also just in case it comes back but is still spawning other procs.
0
 
prashant_khannaAuthor Commented:
Thanx will try it out and let u know.
0
 
jgiordanoCommented:
Any luck
0
 
stokesj56Commented:
Not knowing more specifics about what each of these startup scripts are launching I can't write a complete script. This will work if you substitute the command names of the process that is RUNNING for each of these called scripts (AdminProcess, EjbProcess, & PortalProcess). Code follows:

#!/bin/ksh
watchloop() {
    # Put brackets around 1st character to keep grep from matching itself.
    proc=`echo $1 | sed 's/^\(.\)\(.*\)$/[\1]\2/'`
    echo "proc=$proc"
    ct=0
    maxloop=24
    sleeptime=5
    while [ $ct -lt $maxloop ]
    do
        ps -ef | grep $proc >/dev/null
        if [ $? -eq 0 ]
        then
            #echo "Process found: $1" >&2
            return 0
        fi
        sleep $sleeptime
        let ct+=1
    done
    echo "Process not found: $1" >&2
    return 1
}
startAdminServer.sh
watchloop "AdminProcess" || exit 1
startEjbServer.sh
watchloop "EjbProcess" || exit 2
startPortalServer.sh
watchloop "PortalProcess" || exit 3
# End

Here I have defined a function "watchloop" that waits 2 minutes (5 second sleeps * 24 loops = 120 seconds) for a process to appear in the process table. If found the function will return immediatly with good status (0). If the process in not found by the last loop the function it returns an error status (1).

I then use an "or" (||) operator after the watchloop call that causes the script to exit if the function return is not 0. This will make sure they start in order and if one fails the following scripts will not be launched. I set the exit status different for each launched process. That way if calling from another script you can test the status and know which one failed.

Alternatively, if these are starting network listeners you could use netstat instead of the ps command. I.E.

netstat -an | grep LISTEN | grep "\*\.80" >/dev/null

Would test for an active listener on port 80 (http).



0
 
jgiordanoCommented:
Any luck with this? Long time haven't heard anything.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 9
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now