#!/bin/bash # set -x; # ####################################################################################### # Search for the BEGIN and END lines of yesterdays run of storeBackup in the log file # ####################################################################################### # FUNCTIONS f_makeyesterdaysdate(){ local RETURNVALUE=$(date -d "yesterday 13:00" '+%Y\.%m\.%d'); echo ${RETURNVALUE}; } # VARIABLES YESTERDAYSDATE=$(f_makeyesterdaysdate); SOURCEDIR="/var/samba/heiko/\.storeBackup/everything"; TARGETDIR="/backup-extern-4TB/everything"; NEEDLE1="BEGIN[[:blank:]]+${YESTERDAYSDATE}[[:blank:]]+[[:digit:]]+:[[:digit:]]+:[[:digit:]]+[[:blank:]]+[[:digit:]]+ backing up directory <${SOURCEDIR}> to <${TARGETDIR}>"; NEEDLE2="END[[:blank:]]+${YESTERDAYSDATE}[[:blank:]]+[[:digit:]]+:[[:digit:]]+:[[:digit:]]+[[:blank:]]+[[:digit:]]+ backing up directory <${SOURCEDIR}> to <${TARGETDIR}/${YESTERDAYSDATE}_[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+>"; LOGONE="/var/log/storeBackup/backup-everything.log"; LOGTWO="/var/log/storeBackup/backup-everything.log.1"; MESSAGEBEGINSTATUS="0"; MESSAGEENDSTATUS="0"; MESSAGEBEGIN="BEGIN FOUND!"; MESSAGEEND="END FOUND!"; # Find yesterdays BEGIN if ! grep -E -q "${NEEDLE1}" "${LOGONE}" && ! grep -E -q "${NEEDLE1}" "${LOGTWO}"; then MESSAGEBEGINSTATUS="1"; MESSAGEBEGIN="BEGIN NOT FOUND!"; fi # Find yesterdays END if ! grep -E -q "${NEEDLE2}" "${LOGONE}" && ! grep -E -q "${NEEDLE2}" "${LOGTWO}"; then MESSAGEENDSTATUS="1"; MESSAGEEND="END NOT FOUND!"; fi # Throw a message printf "${MESSAGEBEGIN}\n${MESSAGEEND}\n"; # Exit with status if [ "$((${MESSAGEBEGINSTATUS}+${MESSAGEENDSTATUS}))" -gt "0" ]; then exit 1; fi exit 0;