Created
February 8, 2013 22:22
-
-
Save adam12/4742440 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 | |
### 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