Skip to content

Instantly share code, notes, and snippets.

@euch
Last active October 10, 2022 11:39
Show Gist options
  • Select an option

  • Save euch/76ac478211e86f07d6a049661aff81aa to your computer and use it in GitHub Desktop.

Select an option

Save euch/76ac478211e86f07d6a049661aff81aa to your computer and use it in GitHub Desktop.
Fake 'ping' for TCP-only environments. Return exit 0 if target port 22 is available.
#!/bin/sh
PORT=22
HOST="${BASH_ARGV[0]}"
echo -e Pinging $HOST on port $PORT over TCP
if nc -z -v -w5 $HOST $PORT >/dev/null 2>&1;
then
echo "OK"
exit 0
else
echo "Connection failed"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment