Skip to content

A pure shell script waiting for provided command to exit with zero code

Notifications You must be signed in to change notification settings

vitalets/wait-for-cmd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

wait-for-cmd

A pure shell script waiting for provided command to exit with zero code. Inspired by eficode/wait-for but allows to use any custom command instead of netcat.

Installation

There are two options:

  • download script wait-for-cmd.sh:

    wget https://raw.githubusercontent.com/vitalets/wait-for-cmd/master/wait-for-cmd.sh
    chmod +x ./wait-for-cmd.sh
    
  • run as docker container:

    docker run --rm vitalets/wait-for-cmd 'curl -f https://example.com > /dev/null 2>&1'
    

Usage

./wait-for-cmd.sh COMMAND [TIMEOUT]

Examples

Wait for HOST:PORT ready with netcat:

./wait-for-cmd.sh 'nc -z example.com 80 > /dev/null 2>&1'

Wait for HTTP status 2xx with curl:

./wait-for-cmd.sh 'curl -f https://example.com > /dev/null 2>&1'

Wait for HTTP status 2xx with wget:

./wait-for-cmd.sh 'wget --timeout=1 -q https://example.com -O /dev/null > /dev/null 2>&1'

Wait for Docker container running (note $ before command):

./wait-for-cmd.sh $'[ "$(docker inspect my_container -f \'{{.State.Status}}\')" == "running" ]'

Wait for Docker container healthy (note $ before command):

./wait-for-cmd.sh $'[ "$(docker inspect my_container -f \'{{.State.Health.Status}}\')" == "healthy" ]'

Wait for localhost:port from inside Docker container (note host.docker.internal instead of localhost):

docker run --rm vitalets/wait-for-cmd 'curl -f http://host.docker.internal:3000 > /dev/null 2>&1'

Related projects

Development

Test

./test.sh

Build image

docker build -t vitalets/wait-for-cmd .

Push image

docker push vitalets/wait-for-cmd

License

MIT @ Vitaliy Potapov

About

A pure shell script waiting for provided command to exit with zero code

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published