Skip to content

Instantly share code, notes, and snippets.

@mmrwoods
Last active September 2, 2021 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mmrwoods/ff8618de00d9a289faff505935ab621f to your computer and use it in GitHub Desktop.
Save mmrwoods/ff8618de00d9a289faff505935ab621f to your computer and use it in GitHub Desktop.
Quick hack to check a remote host is accepting connections on a tcp port (useful when doing dangerous things, like kernel updates!)
#!/bin/bash
if [ "$1" == "" ] || [ "$2" == "" ]; then
echo "usage: $0 [options] <host> <port>"
echo
echo "options:"
echo " -i <interval> Number of seconds between checks [default: 5]"
exit 1
fi
interval=5
getopts ":i:" opt
if [ "$opt" == "i" ]; then
interval=$OPTARG
fi
shift $((OPTIND-1))
while true; do
output=`nc -z -G 5 $1 $2 2>&1`
echo `date +%H:%M:%S` $output
sleep $interval
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment