Last active
March 26, 2019 17:39
-
-
Save cfstras/ef840e2980acc8fadeb91bd958c249ca to your computer and use it in GitHub Desktop.
Simple bash function to watch the output of a command and show it when the output changes
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
function watch_change() { | |
local stat | |
local oldstat | |
local lasttime | |
lasttime=$SECONDS | |
while true; do | |
stat="$(eval "$@")" | |
if [[ "$stat" != "$oldstat" ]]; then | |
oldstat="$stat" | |
diff=$((SECONDS-lasttime)) | |
echo -e "\n---\nChanged: (+$diff s)\n$stat" | |
lasttime=$SECONDS | |
fi | |
sleep 0.1 | |
done | |
} | |
watch_change "sudo netstat -tulpena | grep -i Sample" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment