Last active
May 23, 2021 15:22
-
-
Save keylase/4d37ad2931af8ed8315acc9f9d2404f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
inputPeriod=$1 | |
runCommand=$2 | |
RUN_TIME=60 | |
RUN_TIME_LEFT=1 | |
error="no" | |
SECONDS=0 | |
if [ 'x'"$runCommand" != 'x' ] | |
then | |
if [ 'x'$inputPeriod != 'x' ] | |
then | |
loops=$(( $RUN_TIME / $inputPeriod )) | |
if [ $loops -eq 0 ] | |
then | |
loops=1 | |
fi | |
for i in $(eval echo {1..$loops}) | |
do | |
$runCommand | |
sleep $inputPeriod | |
RUN_TIME_LEFT=$((RUN_TIME-SECONDS)) | |
if [ $RUN_TIME_LEFT -le 0 ] | |
then | |
break | |
fi | |
done | |
else | |
error="yes" | |
fi | |
else | |
error="yes" | |
fi | |
if [ $error = "yes" ] | |
then | |
echo "runEvery - runs a command every X seconds for a minute" | |
echo "Usage: runEvery.sh <# in seconds < 60> <command to run>" | |
fi |
Sorry but I cant for my life figure out how to post a change request.
Instead of this, it handles the time drift that is created by the program while it runs. For instance if your program run for 4seconds and you want to run it each second. This original will run 60times, once for each second. 60 * 5 = 300. This will make your system have 5 sets of processes run at each time, NOT what you wanted.
My fix is not perfect, but it's a huge improvement.@keylase if you still use this I assume you want to incorporate the changes I made, I assume you will not have any problem understand what the code does.
Thank you! it looks good - fixed 😄
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry but I cant for my life figure out how to post a change request.
Fork with timedrift fix
Instead of this, it handles the time drift that is created by the program while it runs. For instance if your program run for 4seconds and you want to run it each second. This original will run 60times, once for each second. 60 * 5 = 300. This will make your system have 5 sets of processes run at each time, NOT what you wanted.
My fix is not perfect, but it's a huge improvement.
@keylase if you still use this I assume you want to incorporate the changes I made, I assume you will not have any problem understand what the code does.