Skip to content

Instantly share code, notes, and snippets.

Created January 28, 2012 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/1692424 to your computer and use it in GitHub Desktop.
Save anonymous/1692424 to your computer and use it in GitHub Desktop.
check_port ()
{
netstat -tpln 2> /dev/null | sed -E '/^[^t]/ d; s/^([^ ]+ +){3}//; s/ .*$//; s/^.*://;' | grep --color "^$1$" > /dev/null
}
wait_port ()
{
typeset t;
t=$2;
while (( $t > 0 )) && ! check_port $1; do
echo "waiting for port $1 for $t secconds.";
sleep 1s;
(( t-- ));
done;
check_port $1 && echo "Port $1 started." || {
echo "Port $1 was not started";
false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment