0

I have a command which keeps sending messages and I cannot rate limit it. What I want to do is call the command, let it run for 5 seconds, sleep for 1 minute and then call the script again.

Normally I would write:

#!/bin/bash
while :
do
    myCommand 
    sleep 60
done 

What I want to do is:

#!/bin/bash
while :
do
    run myCommand for 5 seconds and stop. 
    sleep 60
done 

I am not limited to bash, if any other scripting language can do this in an easier way, I don't mind exploring that. Note: myCommand Keeps running and has to be interrupted.

user1692342
  • 5,007
  • 11
  • 69
  • 128
  • This is not really a duplicate and if this answer was honestly answered we should consider making the myCommand stoppable with an option opposed to trying to kill a child ... – Mike Q Sep 01 '18 at 01:42

1 Answers1

0

In Python this would be:

import time

while True:
    start = time.time()
    while time.time() <= start + 5:
        do_the_action()
    time.sleep(60)
Mikhail Burshteyn
  • 4,762
  • 14
  • 27