Retries in shell programming.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Retries in shell programming.
# 1  
Old 05-28-2010
Retries in shell programming.

Hello Friends,

I am writng a shell script which will call another script startServer and then execute one more script pingServer to check if the server is up.

As it takes sometimes for the server to start, so I have defined an until loop to check the status of the server until the server is up, by calling the pingServer script again.

I want pingServer script to be executed 4 times in every 4 minutes before terminating the loop.

I've already written a script, so need your guidance and suggestions(mainly in Retries statement) in making the script better.

Code:
 
Scr_Dir=/dise/vclwrk33/J2EEServer/config/ABP-FULL/ABPServer/scripts
Log_File=/tmp/Enabler_Check.log
  Server_Stat=""
  Retries=0
  Retry_Max=4
#Checking if the script is executable by the current process
    if [ -x $Scr_Dir/startServer ]
    then
            echo "Starting the Server now...." >> $Log_File
            $Scr_Dir/startServer > /dev/null 2>&1
             sleep 60
#Until loop to check the status of the server until the server is up
        until [ $Server_Stat = UP ]
        do
              $Scr_Dir/pingServer | grep UP
              if [ $? -eq 0 ]
              then
                      Server_Stat= UP
                      echo "/n Server has been started successfully..../n" >> $Log_File
              else
#Retrying 4 times in every 4 mins
                      Retries=$( expr $Retries + 1 )
                        if [ $Retries -gt $Retry_Max ]
                        then
                             echo "Timed out in starting the Server.." >> $Log_File
                             exit 1
                        else
                             sleep 240
                        fi
             fi
       done
     else
                echo "Error Executing startServer script..." >> $Log_File
                exit 1
     fi

# 2  
Old 05-28-2010
your script looks good to me. you can as well use a while loop and minimize the code as below

Code:
while [ $Retries -lt 4 ]
do
              $Scr_Dir/pingServer | grep UP
              if [ $? -eq 0 ]
              then
                      echo "/n Server has been started successfully..../n" >> $Log_File
                      exit 0
              else
                             Retries=$( expr $Retries + 1 )
                             sleep 240
               fi
done

echo "Timed out in starting the Server.." >> $Log_File



cheers,
Devaraj Takhellambam
This User Gave Thanks to devtakh For This Post:
# 3  
Old 05-28-2010
Thanks Devaraj, this is really helpful.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

2. Shell Programming and Scripting

Shell programming

Hi every one,i am new to unix.Can any one tell me about shell programming.. (1 Reply)
Discussion started by: martina100011
1 Replies

3. Shell Programming and Scripting

Shell programming

Hi i need a favour i have a file which has some trillions of records. The file is like this 11111000000000192831840914000000000000000000000000000 45789899090000000000000000011111111111111111111111111 I want to cut specific postions in each line like cut1-3 and assisgn it to a variable and... (0 Replies)
Discussion started by: richa2.m
0 Replies

4. Shell Programming and Scripting

need help for shell programming

My purpose was to print out all of name of students in a list.First of all,I created a file name "List" in /home/tuan/Desktop/Shell_programming as below Tom Henry Ben Linda Marry And my script "script" is #!/bin/sh path=/home/tuan/Desktop/Shell_programming/List for student in $path... (3 Replies)
Discussion started by: thungmail
3 Replies

5. Shell Programming and Scripting

shell programming

Hi iam new to shell programming. I would like to ask one dought abt the file handling in unix. Iam having a file1 as follows: ASDERFCX1234567890123456 POIUYTRE0098765432123456 BVCXCVBN0955644411111111 File2 ASDERFCX1234567890123456 kill@abc.com ... (8 Replies)
Discussion started by: nivas
8 Replies

6. Solaris

Solaris 2.6:max login retries

HI, I'm on Solaris 2.6. Where do I set the max login retries? Pls help!! (1 Reply)
Discussion started by: mad_chung
1 Replies

7. UNIX for Advanced & Expert Users

Sendmail retries sending to non-existant users

How can i get sendmail to immediately bounce mail when the server on the other side gives a "550 unknown user" SMTP error? Currently, the outbound mail stays in the queue and is retried until our server gives up, some days later. (0 Replies)
Discussion started by: vertigo23
0 Replies

8. Shell Programming and Scripting

Shell Programming

Provides a menu structure that allows a user to select several options - input a name and address, lookup a name and address, delete a name and address, and print a formatted report from a text database (note: this requirement assumes that you will use the program to create a database, though in... (1 Reply)
Discussion started by: DonOmar
1 Replies

9. Shell Programming and Scripting

Shell Programming?

For what purposes should we use shell /what are the tasks we can achieve using shell which is best book to learn shell programming and will nayone tell me diff between shell programming aand shell scripting? Thank u in advance. (1 Reply)
Discussion started by: shrikrishna
1 Replies

10. UNIX for Dummies Questions & Answers

Shell Programming Help

Hi, I am new to shell programming, and hve been given a request to write a shell script. Is there any good places to go to see examples of how to write shell programming scripts? Thanks (4 Replies)
Discussion started by: mec585858
4 Replies
Login or Register to Ask a Question