-
-
Save AndreasGrip/1a9f8f6e08e235b5c3b6a8a47ba2a8a9 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