From 1a00de8c13716b4eccf4e4809a4493d9346da05d Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Fri, 4 Aug 2023 10:16:54 +0200 Subject: [PATCH] add check if target is reachable --- app.sh | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app.sh b/app.sh index 4d331ea..61dbce4 100644 --- a/app.sh +++ b/app.sh @@ -62,13 +62,18 @@ while true ; do echo "Error: can not export $FQDN config" exit 2 fi - echo "export $FQDN config..." - ssh -n -o StrictHostKeyChecking=no -i "$SSH_KEY_PATH" "${USERNAME}@${FQDN}" "/export show-sensitive" > "config_${FQDN}.rsc" 2> /dev/null - # entferne Datumszeile - sed -i -r '/^# [0-9]{4}-[0-9]{2}-[0-9]{2}\s[0-9]{2}\:[0-9]{2}\:[0-9]{2}\sby\sRouterOS\s[0-9\s\.]+/d' "config_${FQDN}.rsc" - git add "config_${FQDN}.rsc" - echo "commit config for ${FQDN} ..." - git commit -m "update config_${FQDN}" --quiet > /dev/null + # check if target is reachable + if ping -c1 -W1 "${FQDN}" > /dev/null; then + echo "export $FQDN config..." + ssh -n -o StrictHostKeyChecking=no -i "$SSH_KEY_PATH" "${USERNAME}@${FQDN}" "/export show-sensitive" > "config_${FQDN}.rsc" 2> /dev/null + # entferne Datumszeile + sed -i -r '/^# [0-9]{4}-[0-9]{2}-[0-9]{2}\s[0-9]{2}\:[0-9]{2}\:[0-9]{2}\sby\sRouterOS\s[0-9\s\.]+/d' "config_${FQDN}.rsc" + git add "config_${FQDN}.rsc" + echo "commit config for ${FQDN} ..." + git commit -m "update config_${FQDN}" --quiet > /dev/null + else + echo "${FQDN} not reachable!" + fi done <<< "$DEVICES" echo "push config(s)..."