From 857cd771838f7d22df505e51bf2e325285e1d8bc Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Fri, 4 Aug 2023 10:22:34 +0200 Subject: [PATCH] format log output --- app.sh | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/app.sh b/app.sh index 61dbce4..0244bb0 100644 --- a/app.sh +++ b/app.sh @@ -5,45 +5,45 @@ git config --global user.email "$GIT_USER_MAIL" git config --global user.name "$GIT_USERNAME" - echo "clone repository..." + echo "[INFO] clone repository..." GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=no -i $GIT_REPO_DEPLOY_KEY" git clone "$GIT_REPO_URL" "$GIT_REPO_PATH" --quiet > /dev/null cd "$GIT_REPO_PATH" || exit while true ; do - echo "pull repository..." + echo "[INFO] pull repository..." git pull --quiet &> /dev/null echo "check variables..." if [ -z "$INTERVAL" ] ; then - echo "INTERVAL is not set." + echo "[ERROR] \$INTERVAL is not set." exit 3 fi if [ -z "$GIT_REPO_BRANCH" ] ; then - echo "GIT_REPO_BRANCH is not set." + echo "[ERROR] \$GIT_REPO_BRANCH is not set." exit 3 fi if [ -z "$GIT_USERNAME" ] ; then - echo "GIT_USERNAME is not set." + echo "[ERROR] \$GIT_USERNAME is not set." exit 3 fi if [ -z "$GIT_USER_MAIL" ] ; then - echo "GIT_USER_MAIL is not set." + echo "[ERROR] \$GIT_USER_MAIL is not set." exit 3 fi if [ -z "$GIT_REPO_REMOTE_NAME" ] ; then - echo "GIT_REPO_REMOTE_NAME is not set." + echo "[ERROR] \$GIT_REPO_REMOTE_NAME is not set." exit 3 fi if [ -z "$DEVICES" ] ; then - echo "DEVICES is not set." + echo "[ERROR] \$DEVICES is not set." exit 3 fi if [ -z "$GIT_REPO_DEPLOY_KEY" ] ; then - echo "GIT_REPO_DEPLOY_KEY is not set." + echo "[ERROR] \$GIT_REPO_DEPLOY_KEY is not set." exit 3 fi if [ -z "$GIT_REPO_URL" ] ; then - echo "GIT_REPO_URL is not set." + echo "[ERROR] \$GIT_REPO_URL is not set." exit 3 fi @@ -58,32 +58,32 @@ while true ; do FQDN=$(echo "$FQDN" | tr -d "[:space:]") # prüfe ob Key existiert if [ ! -e "$SSH_KEY_PATH" ] ; then - echo "Error: File $SSH_KEY_PATH does not exist" - echo "Error: can not export $FQDN config" + echo "[ERROR] File $SSH_KEY_PATH does not exist" + echo "[ERROR] can not export $FQDN config" exit 2 fi # check if target is reachable if ping -c1 -W1 "${FQDN}" > /dev/null; then - echo "export $FQDN config..." + echo "[INFO] 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} ..." + echo "[INFO] commit config for ${FQDN} ..." git commit -m "update config_${FQDN}" --quiet > /dev/null else - echo "${FQDN} not reachable!" + echo "[ERROR] ${FQDN} not reachable!" fi done <<< "$DEVICES" - echo "push config(s)..." + echo "[INFO] push config(s)..." GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=no -i $GIT_REPO_DEPLOY_KEY" git push > /dev/null # Restore the original IFS value IFS=$OLD_IFS # loop - echo "sleep..." + echo "[INFO] sleep..." sleep "$INTERVAL" done