CheckConn 556 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env bash
  2. # shellcheck shell=bash
  3. # ``````````````````````````````````````````````````````````````````````````````
  4. # Function name: CheckConn()
  5. #
  6. # Description:
  7. # Check connection to remote host.
  8. #
  9. # Usage:
  10. # CheckConn host port
  11. #
  12. # Examples:
  13. # CheckConn 172.20.20.50 22
  14. #
  15. function CheckConn() {
  16. # shellcheck disable=SC2034
  17. local _FUNCTION_ID="CheckConn"
  18. local _STATE=0
  19. local _port="$1"
  20. # shellcheck disable=SC2154
  21. timeout 1 bash -c "</dev/tcp/127.0.0.1/${_port}" >>"$_log_stdout" 2>&1
  22. _STATE="$?"
  23. return $_STATE
  24. }