Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i have installed MySQL NDB cluster. It needs around 2-3 minutes to synchronise the database in between cluster nodes. Once the synchronisation finished only, I can start another application called heartbeat. Therefore in my shell script, I want to check the availability of the ndbd service all the times. Once this service become available, I need to start the heartbeat application in five minute time. Could you please help me to write the script.

share|improve this question

migrated from Jul 14 '09 at 22:57

This question came from our site for professional and enthusiast programmers.

You could also try using the "wait" bash built-in command.

From "man bash"

wait [n]

Wait for the specified process and return its termination status. n may be a process ID or a job specification; if a job spec is given, all processes in that job’s pipeline are waited for. If n is not given, all currently active child processes are waited for, and the return status is zero. If n specifies a non-existent process or job, the return status is 127. Otherwise, the return status is the exit status of the last process or job waited for.

You script could look something like this:

# send to background
./ndb_startup_script & 

# wait on pid of ndb_startup_script
wait $!

if [ $? -eq 0 ] # assuming 0 is ret code for successful run
    # extra stuff to handle error
share|improve this answer

What I'd to is have the ndb script exec another script, so that it's not waiting for the 5 minutes to finish and blocking other services from starting.

## whatever starts ndb
exec heartbeat_startup_script

I've put a sleep 300 (seconds) in here, cause you've specified 5 minutes, but checking if the ndb sync is done would be much better.

sleep 300
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.