
Ich möchte die Ausgabe so drosseln, dass sie grep
höchstens alle X Sekunden ausgeführt wird. Genauer gesagt möchte ich so etwas tun:
ping 8.8.8.8 | grep "No route to host" | throttle 3s | xargs -I % sh -c 'reset wifi'
Antwort1
Beantwortung meiner eigenen Frage, basierend aufdiese Frage, aber leicht geändert für OSX:
epoch () { date -v+$* "+%s" }
interval () {
INTERVAL="$*"
WHEN_TO_RUN=0
while read LINE; do
if (( $(epoch 0S) >= $WHEN_TO_RUN )) then
echo $LINE
WHEN_TO_RUN="$(epoch $INTERVAL)"
fi
done
}
welches erlaubt... | interval 3S