From fe639f6c6327b3f968b93aff12778660b17ad7a7 Mon Sep 17 00:00:00 2001 From: Kevin Krotzer Date: Tue, 7 Feb 2023 17:43:23 -0800 Subject: [PATCH] Add automatic retry Co-authored-by: Kevin Krotzer Co-authored-by: Zach Butler --- entry.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/entry.sh b/entry.sh index 05c8f9f..efd1d62 100755 --- a/entry.sh +++ b/entry.sh @@ -1,9 +1,17 @@ #!/bin/sh while true; do - DATE="$(date)" + RUN_TIME="$(date '+%s')" # shellcheck disable=SC2086 /zap2xml.pl -u "$USERNAME" -p "$PASSWORD" -U -o "/data/$XMLTV_FILENAME" $OPT_ARGS - echo "Last run time: $DATE" - echo "Will run in $SLEEPTIME seconds" - sleep "$SLEEPTIME" + printf 'Run time: ' + date -d "@$RUN_TIME" '+%F %T %Z' + MOD_TIME="$(date -r "/data/$XMLTV_FILENAME" '+%s')" + if test "$MOD_TIME" -gt "$RUN_TIME"; then + echo "Will run again in $SLEEPTIME seconds." + sleep "$SLEEPTIME" + else + echo 'This run did not complete successfully.' + echo 'Pausing for 30 seconds and trying again...' + sleep 30 + fi done