Created
November 12, 2015 08:58
-
-
Save jsarenik/de1b3809bc62a1ce351e to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
ifthere() { | |
for cmd in "$@" | |
do | |
type ${cmd%% *} >/dev/null 2>&1 && { $cmd || continue; return $?; } | |
done | |
} | |
usage() { | |
cat >&2 <<-EOF | |
Usage: $0 [OPTION]... | |
Print CPU, memory or disk utilization using available tools. | |
Options: | |
-m Memory | |
-p or -c Processor (CPU) | |
-d Disk | |
EOF | |
} | |
while getopts "mpcdh" opt; do | |
case $opt in | |
m) | |
ifthere \ | |
free \ | |
vm_stat | |
;; | |
p|c) | |
ifthere \ | |
sar \ | |
mpstat \ | |
"ps -e -o pcpu -o pid -o user -o args" | |
;; | |
d) | |
ifthere \ | |
df | |
;; | |
*) | |
usage | |
;; | |
esac | |
done | |
test $# -lt 1 && usage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment