megafono_bot.sh 926 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. DATA_FILE=megafono.txt
  10. #
  11. # CONFIGURATION END
  12. #
  13. random_time_on_range(){
  14. FLOOR=$1
  15. CEILING=$2
  16. RANGE=$(($CEILING-$FLOOR+1));
  17. #echo "You will generate a random number between $FLOOR and $CEILING (both inclusive). There are $RANGE possible numbers!"
  18. RESULT=$RANDOM;
  19. #echo "We just generated the random number $RESULT, which might not be in the range we want";
  20. let "RESULT %= $RANGE";
  21. RESULT=$(($RESULT+$FLOOR));
  22. echo $RESULT;
  23. }
  24. while :
  25. do
  26. # Last line should be empty, so we dont need an additional read here
  27. # after the while loop
  28. while read line
  29. do
  30. eval ./toot.sh $line
  31. SLEEP_TOOT=$(random_time_on_range $FLOOR_HOUR_SLEEP_INTERVAL $CEILING_HOUR_SLEEP_INTERVAL)
  32. sleep $SLEEP_TOOT"h"
  33. done < ${DATA_FILE}
  34. done