Skip to content

Instantly share code, notes, and snippets.

@cfstras
Last active March 26, 2019 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cfstras/ef840e2980acc8fadeb91bd958c249ca to your computer and use it in GitHub Desktop.
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
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