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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! it looks good - fixed 😄