Solved

Startup shell script

Posted on 2004-10-08
18
665 Views
Last Modified: 2008-03-17
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
Comment
Question by:prashant_khanna
  • 9
  • 5
18 Comments
 
LVL 11

Expert Comment

by:jgiordano
ID: 12263095
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
 

Author Comment

by:prashant_khanna
ID: 12263125
How do i do that ?
0
 
LVL 11

Expert Comment

by:jgiordano
ID: 12263138
Give me 5 minutes and I will write it; I am in the middle of something else
0
 

Author Comment

by:prashant_khanna
ID: 12263184
Alright, would be waiting for your reply.

Thanx


0
 
LVL 11

Expert Comment

by:jgiordano
ID: 12263248
quick question how do you start these regular? do you add any parameters? or do you just execute startAdminServer.sh
0
 

Author Comment

by:prashant_khanna
ID: 12263260
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
 
LVL 11

Expert Comment

by:jgiordano
ID: 12263280
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 11

Expert Comment

by:jgiordano
ID: 12263290
also what do you execute to validate that the server is RUNNING
0
 

Author Comment

by:prashant_khanna
ID: 12263362
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
 
LVL 11

Accepted Solution

by:
jgiordano earned 50 total points
ID: 12263398
#!/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
 
LVL 11

Expert Comment

by:jgiordano
ID: 12263407
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
 

Author Comment

by:prashant_khanna
ID: 12263438
Thanx will try it out and let u know.
0
 
LVL 11

Expert Comment

by:jgiordano
ID: 12280835
Any luck
0
 
LVL 2

Assisted Solution

by:stokesj56
stokesj56 earned 50 total points
ID: 12282047
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
 
LVL 11

Expert Comment

by:jgiordano
ID: 12590473
Any luck with this? Long time haven't heard anything.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction Often we come across situations wherein our batch files would be needing to reboot Windows for a variety of reasons. A few of them would be like: (1) Setup files have been updated whose changes can take effect only after a reboot …
In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now