From e5f2ee0e309ddf5e6a6150928fd8492f14bed3fd Mon Sep 17 00:00:00 2001 From: adrianp Date: Thu, 31 Mar 2022 14:37:38 +0300 Subject: [PATCH] For system where there is no datediff, use the alternate name --- borg_exporter.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/borg_exporter.sh b/borg_exporter.sh index 76e42b9..ebd5e91 100755 --- a/borg_exporter.sh +++ b/borg_exporter.sh @@ -3,6 +3,11 @@ source /etc/borg_exporter.rc TMP_FILE=$(mktemp /tmp/prometheus-borg-XXXXX) +DATEDIFF=`which datediff` +if [ -z "$DATEDIFF" ]; then + #ubuntu packages have a different executable name + DATEDIFF=`which dateutils.ddiff` +fi [ -e $TMP_FILE ] && rm -f $TMP_FILE @@ -57,7 +62,7 @@ function getBorgDataForRepository { LAST_ARCHIVE_DATE=$(echo $LAST_ARCHIVE | awk '{print $3" "$4}') LAST_ARCHIVE_TIMESTAMP=$(date -d "$LAST_ARCHIVE_DATE" +"%s") CURRENT_DATE="$(date '+%Y-%m-%d %H:%M:%S')" - NB_HOUR_FROM_LAST_BCK=$(datediff "$LAST_ARCHIVE_DATE" "$CURRENT_DATE" -f '%H') + NB_HOUR_FROM_LAST_BCK=$($DATEDIFF "$LAST_ARCHIVE_DATE" "$CURRENT_DATE" -f '%H') # in case the date parsing from BORG didn't work (e.g. archive with space in it), datediff will output # a usage message on stdout and will break prometheus formatting. We need to