-
-
Save cdpath/cf60b448df5d62bd185698b79a6e18c9 to your computer and use it in GitHub Desktop.
handlers for hubot-script-shellcmd
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
#!/usr/bin/env bash | |
set -o errexit | |
cmd_type=$1 | |
do_top() { | |
top -b -n2 -p 1 | fgrep "Cpu(s)" | tail -1 | awk -F'id,' -v prefix="$prefix" '{ split($1, vs, ","); v=vs[length(vs)]; sub("%", "", v); printf "%s%.1f%%\n", prefix, 100 - v }' | |
} | |
do_who() { | |
who | awk '{print $1}' | |
} | |
case "${cmd_type}" in | |
top|who) | |
do_${1} | |
;; | |
*) | |
echo "Please specify top or who as the second arg" | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment