megafono_bot.sh 969 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/bash
  2. #
  3. # CONFIGURATION
  4. #
  5. # Interval between two consecutive posts
  6. FLOOR_HOUR_SLEEP_INTERVAL=5
  7. CEILING_HOUR_SLEEP_INTERVAL=19
  8. # File containing the toots to post
  9. if [ ! -z "$1" ]; then
  10. DATA_FILE=$1
  11. else
  12. DATA_FILE=megafono.txt
  13. fi
  14. # CONFIGURATION END
  15. #
  16. random_time_on_range(){
  17. FLOOR=$1
  18. CEILING=$2
  19. RANGE=$(($CEILING-$FLOOR+1));
  20. #echo "You will generate a random number between $FLOOR and $CEILING (both inclusive). There are $RANGE possible numbers!"
  21. RESULT=$RANDOM;
  22. #echo "We just generated the random number $RESULT, which might not be in the range we want";
  23. let "RESULT %= $RANGE";
  24. RESULT=$(($RESULT+$FLOOR));
  25. echo $RESULT;
  26. }
  27. while :
  28. do
  29. # Last line should be empty, so we dont need an additional read here
  30. # after the while loop
  31. while read line
  32. do
  33. eval ./toot.sh $line
  34. SLEEP_TOOT=$(random_time_on_range $FLOOR_HOUR_SLEEP_INTERVAL $CEILING_HOUR_SLEEP_INTERVAL)
  35. sleep $SLEEP_TOOT"h"
  36. done < ${DATA_FILE}
  37. done