Skip to content

Instantly share code, notes, and snippets.

@paullaffitte
Last active October 13, 2018 20:35
Show Gist options
  • Save paullaffitte/c328089599f590e6fc25b05d2bdca927 to your computer and use it in GitHub Desktop.
Save paullaffitte/c328089599f590e6fc25b05d2bdca927 to your computer and use it in GitHub Desktop.
Script execution limiter
#! /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