Skip to content

Instantly share code, notes, and snippets.

@adam12
Created February 8, 2013 22:22
Show Gist options
  • Save adam12/4742440 to your computer and use it in GitHub Desktop.
Save adam12/4742440 to your computer and use it in GitHub Desktop.
#!/bin/bash
### Run with
# while (nc -e info.sh -v -l -p 1025); do sleep 1; done
#
users() {
who | cut -f1 -d ' ' | uniq | awk -v ORS=, '{ print "\042"$1"\042" }' | sed 's/,$//'
}
ips() {
ifconfig | grep 'inet addr:' | grep -v '127.0.0.1' | cut -d: -f2 | awk -v ORS=, '{ print "\042"$1"\042" }' | sed 's/,$//'
}
memory() {
free -m | grep Mem: | awk '{ print "\042used\042:" $3 "," "\042free\042:" $4 "," "\042total\042:" $2 }'
}
disk() {
df -TP | grep -v Filesystem | grep -v tmpfs | awk -v ORS=, '{ print "\042" $1 "\042" ":{" "\042total\042:" $3 "," "\042used\042:" $4 "," "\042available\042:" $5 "}" }' | sed 's/,$//'
}
printf '{"hostname":"%s","ips":{%s},users":{%s},"memory":{%s},"disk":{%s}}\n' "$(hostname)" "$(ips)" "$(users)" "$(memory)" "$(disk)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment