The following code-snippet is a shell-script which does the following:
Track the time for a block of shell commands
Check if the time was less than x seconds (the example uses 10 seconds)
If the block run through too fast the script waits/sleeps a few seconds
Run all this within a loop so that the block of shell-commands is executed periodically
I used the script combined with a PHP script which processes a queue. The PHP script processes 1000 elements from the queue and takes about 30 seconds for that. Since just having a cronjob per minute would be not efficient enought I used this script.
The waiting-block is necessary because now and then the queue is empty … but I think there are lot’s of situations where a script like this can be usefull:
while [ 1 -ge 0 ]; do
###BLOCK 2 TRACK - BEGIN
let "number %= 20"
###BLOCK 2 TRACK - END
if [[ $total -ge 10 ]]; then
echo "time taken was: $number : $total"
echo "time take was too less $number : $total"