From 4383a9769c57f74c7b8980b7a78b12703482a2d2 Mon Sep 17 00:00:00 2001 From: jops Date: Sun, 24 Feb 2019 00:33:29 +0100 Subject: [PATCH] range orario su sintesi da discussione https://mastodon.bida.im/@pepsy/101625232756630453 --- megafono_bot.sh | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/megafono_bot.sh b/megafono_bot.sh index 988e04b..a70c6ff 100755 --- a/megafono_bot.sh +++ b/megafono_bot.sh @@ -5,7 +5,8 @@ # # Interval between two consecutive posts -SLEEP_INTERVAL=3h +FLOOR_HOUR_SLEEP_INTERVAL=5 +CEILING_HOUR_SLEEP_INTERVAL=19 # File containing the toots to post DATA_FILE=megafono.txt @@ -14,14 +15,28 @@ DATA_FILE=megafono.txt # CONFIGURATION END # +random_time_on_range(){ + FLOOR=$1 + CEILING=$2 + RANGE=$(($CEILING-$FLOOR+1)); + #echo "You will generate a random number between $FLOOR and $CEILING (both inclusive). There are $RANGE possible numbers!" + RESULT=$RANDOM; + #echo "We just generated the random number $RESULT, which might not be in the range we want"; + let "RESULT %= $RANGE"; + RESULT=$(($RESULT+$FLOOR)); + echo $RESULT; +} + + while : do # Last line should be empty, so we dont need an additional read here # after the while loop while read line do - eval ./toot.sh $line - sleep ${SLEEP_INTERVAL} + #eval ./toot.sh $line + SLEEP_TOOT=$(random_time_on_range $FLOOR_HOUR_SLEEP_INTERVAL $CEILING_HOUR_SLEEP_INTERVAL) + sleep $SLEEP_TOOT"h" done < ${DATA_FILE} -done \ No newline at end of file +done