Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- function testSshConnection() {
- local SSH_CMD="ssh -o BatchMode=yes -o ConnectTimeout=3 $1@$2 2>&1 | grep "Host key verification failed.""
- echo "RUNNING: $SSH_CMD"
- $SSH_CMD
- PIPE_RESULT="${PIPESTATUS[0]} ${PIPESTATUS[1]}"
- echo "FUNCTION: PIPE_RESULT: ${PIPE_RESULT}"
- PIPE_RESULT_ARRAY=($PIPE_RESULT)
- PIPE0="${PIPE_RESULT_ARRAY[0]}"
- PIPE1="${PIPE_RESULT_ARRAY[1]}"
- local RC=${PIPE1:-$PIPE0}
- echo "Returning RC=$RC"
- return $RC
- }
- while ! testSshConnection root $1; do
- PIPE_RESULT="${PIPESTATUS[0]} ${PIPESTATUS[1]}"
- echo "WHILE: PIPE_RESULT: ${PIPE_RESULT}"
- PIPE_RESULT_ARRAY=($PIPE_RESULT)
- PIPE0="${PIPE_RESULT_ARRAY[0]}"
- PIPE1="${PIPE_RESULT_ARRAY[1]}"
- WAIT=4
- echo "Waiting $SLEEP seconds for host $1 to be accessible on port 22"
- sleep $WAIT
- done
- exit
- ~ $ /tmp/test.sh 46.101.7.220
- RUNNING: ssh -o BatchMode=yes -o ConnectTimeout=3 root@46.101.7.220 2>&1 | grep "Host key verification failed."
- Host key verification failed.
- FUNCTION: PIPE_RESULT: 255
- Returning RC=255
- WHILE: PIPE_RESULT: 255
- Waiting 4 seconds for host 46.101.7.220 to be accessible on port 22
- RUNNING: ssh -o BatchMode=yes -o ConnectTimeout=3 root@46.101.7.220 2>&1 | grep "Host key verification failed."
- Host key verification failed.
- FUNCTION: PIPE_RESULT: 255
- Returning RC=255
- WHILE: PIPE_RESULT: 255
- ...etc
- ~ $ ssh -o BatchMode=yes -o ConnectTimeout=3 root@46.101.7.220 2>&1 | grep "Host key verification failed."
- Host key verification failed.
- ~ $ echo "${PIPESTATUS[0]} ${PIPESTATUS[1]}"
- 255 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement