Skip to content

Instantly share code, notes, and snippets.

@Gerst20051
Last active November 17, 2022 05:32
Show Gist options
  • Save Gerst20051/99c1cf570a2d0d59f09339a806732fd3 to your computer and use it in GitHub Desktop.
Save Gerst20051/99c1cf570a2d0d59f09339a806732fd3 to your computer and use it in GitHub Desktop.
Bash Watch Command
# execute commands at a specified interval of seconds
function watch.command {
# USAGE: watch.commands [seconds] [commands...]
# EXAMPLE: watch.command 5 date
# EXAMPLE: watch.command 5 date echo 'ls -l' echo 'ps | grep "kubectl\\\|node\\\|npm\\\|puma"'
# EXAMPLE: watch.command 5 'date; echo; ls -l; echo; ps | grep "kubectl\\\|node\\\|npm\\\|puma"' echo date 'echo; ls -1'
local cmds=()
for arg in "${@:2}"; do
echo $arg | sed 's/; /;/g' | tr \; \\n | while read cmd; do
cmds+=($cmd)
done
done
while true; do
clear
for cmd in $cmds; do
eval $cmd
done
sleep $1
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment