Created
December 14, 2017 07:47
-
-
Save cirias/e86e6425e98b20ff93b39af013d12b70 to your computer and use it in GitHub Desktop.
watch and execute
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 | |
# monitor STDIN | |
# run command when interval of lines come in smaller than sepecific duration | |
DURATION=2 # in seconds | |
LINES_COUNT=1 | |
COMMAND="echo Aha!" | |
SECONDS=$DURATION | |
COUNTER=$LINES_COUNT | |
while true; do | |
read line | |
if (( SECONDS >= DURATION )); then | |
SECONDS=0 | |
COUNTER=$LINES_COUNT | |
continue | |
fi | |
COUNTER=$((COUNTER-1)) | |
if (( COUNTER <= 0 )); then | |
eval $COMMAND | |
SECONDS=$DURATION | |
COUNTER=$LINES_COUNT | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment