Skip to content

Instantly share code, notes, and snippets.

@harshavardhana
Created June 9, 2014 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harshavardhana/b254474727f185cf921c to your computer and use it in GitHub Desktop.
Save harshavardhana/b254474727f185cf921c to your computer and use it in GitHub Desktop.
Use bash socket to check for host/port connection
#!/bin/bash
function ping_host ()
{
{
exec 4<>/dev/tcp/$1/$2
if [ $? -ne '0' ]; then
echo "Port not reachable"
return 1;
else
return 0;
fi
} 1>&2 2>/dev/null
}
main ()
{
ping_host $1 $2
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment