Created
February 6, 2017 13:03
-
-
Save sebble/a7b26e95970edb7b6d27284829baa699 to your computer and use it in GitHub Desktop.
Run a shell script only once per time interval
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/sh | |
# Configuration | |
INTERVAL=10 # (seconds) | |
LASTRUN=".lastrun" # (optional) | |
# Run_per logic | |
NOW=$(date +%s) | |
test -f "$LASTRUN" && THEN=$(cat "$LASTRUN") || THEN=0 | |
test $INTERVAL -gt $(($NOW - $THEN)) && exit 0 | |
echo -n $NOW > "$LASTRUN" | |
# Your script below | |
# ... |
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/sh | |
# Replace "10" with desired interval in seconds | |
[ -f .lastrun ]&&[ 10 -gt $((`date +%s`-`cat .lastrun`)) ]&&exit 0||date +%s>.lastrun | |
# Your script below | |
# ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment