From bb2aec86467190bbc480a151424e356e41a277cc Mon Sep 17 00:00:00 2001 From: Avi Deitcher Date: Tue, 12 Feb 2019 11:13:16 +0200 Subject: [PATCH] Handle current minute correctly and add test for it --- functions.sh | 6 +++--- test/test_cron.sh | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/functions.sh b/functions.sh index fa7d772f..d1cdb488 100644 --- a/functions.sh +++ b/functions.sh @@ -220,7 +220,7 @@ function wait_for_cron() { # we keep a copy of the actual compare time, because we might shift the compare time in a moment local comparesec=$compare # there must be at least 60 seconds between last run and next run, so if it is less than 60 seconds, - # add 60 seconds to $compare + # add differential seconds to $compare local compareDiff=$(($compare - $last_run)) if [ $compareDiff -lt 60 ]; then compare=$(($compare + $(( 60-$compareDiff )) )) @@ -229,9 +229,9 @@ function wait_for_cron() { # cron only works in minutes, so we want to round down to the current minute # e.g. if we are at 20:06:25, we need to treat it as 20:06:00, or else our waittime will be -25 # on the other hand, if we are at 20:06:00, do not round it down - local current_seconds=$(date --date="@$compare" +"%-S") + local current_seconds=$(date --date="@$comparesec" +"%-S") if [ $current_seconds -ne 0 ]; then - compare=$(( $compare - $current_seconds )) + comparesec=$(( $comparesec - $current_seconds )) fi # reminder, cron format is: diff --git a/test/test_cron.sh b/test/test_cron.sh index a46c6fe4..7ddf3131 100755 --- a/test/test_cron.sh +++ b/test/test_cron.sh @@ -58,17 +58,20 @@ cronline=( "1 * * * *" "1 * * * *" "* 1 * * *" + "1 * * * *" #"10 2 10 * *" ) nowtime=( "2018.10.10-10:01:00" "2018.10.10-10:00:00" "2018.10.10-10:00:00" + "2018.10.10-10:01:10" # this line tests that we use the current minute, and not wait for "-10" ) waittime=( "0" "60" "54000" + "0" ) for ((i=0; i< ${#cronline[@]}; i++)); do