Solved

Startup shell script

Posted on 2004-10-08
18
693 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

 

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
 
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a recent article here at Experts Exchange (http://www.experts-exchange.com/articles/18880/PaperPort-14-in-Windows-10-A-First-Look.html), I discussed my nine-month sandbox testing of the Windows 10 Technical Preview, specifically with respect to r…
In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Suggested Courses

617 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