From bcb9e5e459992a5f4bd01995e1470fe8293b0871 Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Mon, 27 Nov 2023 10:59:08 +1100 Subject: [PATCH] add ONLYFAILED argument (-f) --- report_telegram.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 report_telegram.sh diff --git a/report_telegram.sh b/report_telegram.sh new file mode 100755 index 0000000..7896e2a --- /dev/null +++ b/report_telegram.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# Feed backup status info to a telegram bot + +ONLYFAILED=0 # 0=send full report. 1=report only on failed backups +BARE=/root/scripts/bare/bare.sh +SENDER=/root/scripts/telegram-send/telegram-send.sh + +function usage() { + echo "usage: $0 [OPTIONS]" + echo "Feeds backup status to telegram. " + echo + echo "OPTIONS" + echo " -f Only report on failed backups." + echo +} + +ARGS="hf" + +while getopts "$ARGS" i; do + case "$i" in + f) + ONLYFAILED=1 + ;; + h) + usage; + exit 1 + ;; + *) + echo "ERROR: invalid argument: $i"; + usage; + exit 1 + ;; + esac +done +shift $((OPTIND - 1)) + +text=$($BARE -T -a check) +[[ $ONLYFAILED -eq 1 ]] && text=$(egrep -v '^.*OK.*:' <<<"$text") +if [[ -n $text ]]; then + $SENDER "$text" +fi