You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1000 B

#!/usr/bin/env bash
while true; do
ssh ${@}
echo "Connection lost at $(date +%H:%M:%S)."
for I in {15..1}; do
echo -ne "\rIdling for ${I} seconds... "; sleep 1
done
echo ''
TSTP="$(date +%H:%M:%S)"; dig +time=2 ${@} &> /dev/null; RSLT=${?}
while [ ${RSLT} -ne 0 ]; do
for I in {9..1}; do
echo -ne "\rHost lookup failed at ${TSTP}. Retrying in ${I}... "; sleep 1
done
echo ''
TSTP="$(date +%H:%M:%S)"; dig +time=2 ${@} &> /dev/null; RSLT=${?}
done
echo "Host lookup succeeded at ${TSTP}."
TSTP="$(date +%H:%M:%S)"; ping -c 1 -W 2 ${@} &> /dev/null; RSLT=${?}
while [ ${RSLT} -ne 0 ]; do
for I in {9..1}; do
echo -ne "\rPinging host failed at ${TSTP}. Retrying in ${I}... "; sleep 1
done
echo ''
TSTP="$(date +%H:%M:%S)"; ping -c 1 -W 2 ${@} &> /dev/null; RSLT=${?}
done
echo "Host ping succeeded at ${TSTP}."
for I in {5..1}; do
echo -ne "\rRetrying SSH connection in ${I}... "; sleep 1
done
echo ''
done