Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. function testSshConnection() {
  4. local SSH_CMD="ssh -o BatchMode=yes -o ConnectTimeout=3 $1@$2 2>&1 | grep "Host key verification failed.""
  5. echo "RUNNING: $SSH_CMD"
  6. $SSH_CMD
  7. PIPE_RESULT="${PIPESTATUS[0]} ${PIPESTATUS[1]}"
  8. echo "FUNCTION: PIPE_RESULT: ${PIPE_RESULT}"
  9. PIPE_RESULT_ARRAY=($PIPE_RESULT)
  10. PIPE0="${PIPE_RESULT_ARRAY[0]}"
  11. PIPE1="${PIPE_RESULT_ARRAY[1]}"
  12. local RC=${PIPE1:-$PIPE0}
  13. echo "Returning RC=$RC"
  14. return $RC
  15. }
  16.  
  17. while ! testSshConnection root $1; do
  18. PIPE_RESULT="${PIPESTATUS[0]} ${PIPESTATUS[1]}"
  19. echo "WHILE: PIPE_RESULT: ${PIPE_RESULT}"
  20. PIPE_RESULT_ARRAY=($PIPE_RESULT)
  21. PIPE0="${PIPE_RESULT_ARRAY[0]}"
  22. PIPE1="${PIPE_RESULT_ARRAY[1]}"
  23. WAIT=4
  24. echo "Waiting $SLEEP seconds for host $1 to be accessible on port 22"
  25. sleep $WAIT
  26. done
  27.  
  28. exit
  29.  
  30. ~ $ /tmp/test.sh 46.101.7.220
  31. RUNNING: ssh -o BatchMode=yes -o ConnectTimeout=3 root@46.101.7.220 2>&1 | grep "Host key verification failed."
  32. Host key verification failed.
  33. FUNCTION: PIPE_RESULT: 255
  34. Returning RC=255
  35. WHILE: PIPE_RESULT: 255
  36. Waiting 4 seconds for host 46.101.7.220 to be accessible on port 22
  37. RUNNING: ssh -o BatchMode=yes -o ConnectTimeout=3 root@46.101.7.220 2>&1 | grep "Host key verification failed."
  38. Host key verification failed.
  39. FUNCTION: PIPE_RESULT: 255
  40. Returning RC=255
  41. WHILE: PIPE_RESULT: 255
  42. ...etc
  43.  
  44. ~ $ ssh -o BatchMode=yes -o ConnectTimeout=3 root@46.101.7.220 2>&1 | grep "Host key verification failed."
  45. Host key verification failed.
  46. ~ $ echo "${PIPESTATUS[0]} ${PIPESTATUS[1]}"
  47. 255 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement