Last active
November 17, 2022 05:32
-
-
Save Gerst20051/99c1cf570a2d0d59f09339a806732fd3 to your computer and use it in GitHub Desktop.
Bash Watch Command
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
# 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