abort and log backup if SSH login doesn't work
This commit is contained in:
@@ -30,22 +30,35 @@ source "$CURDIR"/config.cfg
|
|||||||
|
|
||||||
if [ ! -e "$HOSTS" ]; then echo "Missing hosts file. Please set a correct value of HOSTS= in your config file. Current value: $HOSTS"; exit 1; fi
|
if [ ! -e "$HOSTS" ]; then echo "Missing hosts file. Please set a correct value of HOSTS= in your config file. Current value: $HOSTS"; exit 1; fi
|
||||||
|
|
||||||
|
ARG1="$1"
|
||||||
|
|
||||||
function trim {
|
function trim {
|
||||||
sed -r -e 's/^\s*//g' -e 's/\s*$//g'
|
sed -r -e 's/^\s*//g' -e 's/\s*$//g'
|
||||||
}
|
}
|
||||||
|
|
||||||
while read line; do
|
while read line; do
|
||||||
|
# if line is a comment, go to next line
|
||||||
if $(echo "$line" | grep -qE "^\s*#"); then continue; fi
|
if $(echo "$line" | grep -qE "^\s*#"); then continue; fi
|
||||||
|
|
||||||
RHOST=$(echo "$line" | cut -d";" -f1 | trim)
|
RHOST=$(echo "$line" | cut -d";" -f1 | trim)
|
||||||
|
|
||||||
|
if [[ "${ARG1}" != "" ]] && [[ "${ARG1}" != "${RHOST}" ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
echo "[INFO] Trying ${RHOST}"
|
echo "[INFO] Trying ${RHOST}"
|
||||||
|
|
||||||
STATUS=$(ssh -n -o BatchMode=yes -o ConnectTimeout=5 ${RHOST} "echo -n"; echo $?)
|
STATUS=$(ssh -n -o BatchMode=yes -o ConnectTimeout=5 ${RHOST} "echo -n"; echo $?)
|
||||||
|
|
||||||
if [ $STATUS != 0 ]; then
|
if [ $STATUS != 0 ]; then
|
||||||
echo "[ERROR] No SSH login possible for ${RHOST}. Adding public key with password:"
|
echo -n "[ERROR] No SSH login possible for ${RHOST}. "
|
||||||
cat ~/.ssh/id_rsa.pub | ssh ${RHOST} 'cat >> ~/.ssh/authorized_keys'
|
if [[ "${ARG1}" != "" ]]; then
|
||||||
|
echo "Aborting."
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "Adding public key with password: "
|
||||||
|
cat ~/.ssh/id_rsa.pub | ssh ${RHOST} 'cat >> ~/.ssh/authorized_keys'
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "[SUCCESS] SSH login possible for ${RHOST}."
|
echo "[SUCCESS] SSH login possible for ${RHOST}."
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ function logecho {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while read line; do
|
while read line; do
|
||||||
|
# if line is a comment, go to next line
|
||||||
if $(echo "$line" | grep -qE "^\s*#"); then continue; fi
|
if $(echo "$line" | grep -qE "^\s*#"); then continue; fi
|
||||||
|
|
||||||
RHOST=$(echo "$line" | cut -d";" -f1 | trim)
|
RHOST=$(echo "$line" | cut -d";" -f1 | trim)
|
||||||
@@ -55,6 +56,12 @@ while read line; do
|
|||||||
ALLRDIR=$(echo "$line" | cut -d";" -f2 | trim)
|
ALLRDIR=$(echo "$line" | cut -d";" -f2 | trim)
|
||||||
|
|
||||||
logecho "${RHOST}: Starting backups"
|
logecho "${RHOST}: Starting backups"
|
||||||
|
|
||||||
|
if ! "${CURDIR}"/ssh-checker.sh "${RHOST}"; then
|
||||||
|
logecho "${RHOST}: ERROR when connecting via SSH. Please run ssh-checker.sh to debug."
|
||||||
|
logecho "${RHOST}: Aborting backup after an error."
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
NORDIR=$(echo $ALLRDIR | grep -o "|" | wc -l)
|
NORDIR=$(echo $ALLRDIR | grep -o "|" | wc -l)
|
||||||
NORDIR=$[$NORDIR + 1]
|
NORDIR=$[$NORDIR + 1]
|
||||||
|
|||||||
Reference in New Issue
Block a user