Skip to content

Instantly share code, notes, and snippets.

@cdpath
Last active October 18, 2016 08:19
Show Gist options
  • Save cdpath/cf60b448df5d62bd185698b79a6e18c9 to your computer and use it in GitHub Desktop.
Save cdpath/cf60b448df5d62bd185698b79a6e18c9 to your computer and use it in GitHub Desktop.
handlers for hubot-script-shellcmd
#!/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