#!/bin/bash hostport="$1" shift cmd="$@" host="${hostport%%:*}" port="${hostport##*:}" while ! nc -z "$host" "$port"; do echo "Waiting for $host:$port..." sleep 1 done echo "$host:$port is available. Running command: $cmd" exec $cmd