Last active
October 13, 2018 20:35
-
-
Save paullaffitte/c328089599f590e6fc25b05d2bdca927 to your computer and use it in GitHub Desktop.
Script execution limiter
This file contains 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
#! /usr/bin/env bash | |
name=$1 | |
interval=$(echo "$2" | bc) | |
file=~/.limiter/"$name" | |
now=$(date +"%s") | |
if [ ! -f "$file" ] || (( $(echo $now - $(cat "$file") | bc) >= $interval )); then | |
mkdir -p ~/.limiter | |
echo $now > "$file" | |
${@:3} | |
else | |
remainingTime=$(echo $interval - \($now - $(cat $file)\) | bc) | |
echo Remaining time before allowing to start: $remainingTime | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment