Skip to content

Instantly share code, notes, and snippets.

@tavy315
Last active January 13, 2018 01:05
Show Gist options
  • Save tavy315/a6c05e726ee08997c33d05300dbb2cbf to your computer and use it in GitHub Desktop.
Save tavy315/a6c05e726ee08997c33d05300dbb2cbf to your computer and use it in GitHub Desktop.
/usr/local/bin/systemstats.sh
#!/bin/bash
#
# Server Status Script
# Version 0.1.5
# Updated: September 15th 2017
CPUTIME=$(ps -eo pcpu | awk 'NR>1' | awk '{tot=tot+$1} END {print tot}')
CPUCORES=$(cat /proc/cpuinfo | grep -c processor)
UP=$(echo `uptime` | awk '{ print $3 " " $4 }')
echo "
System Status updated: `date`
- Server Name = `hostname`
- Public IP = `dig +short myip.opendns.com @resolver1.opendns.com`
- OS Version = `cat /etc/redhat-release`
- Platform Data = `uname -orpi`
- System Uptime = `echo $UP`
- Load Averages = `cat /proc/loadavg`
- CPU Usage (average) = `echo $CPUTIME / $CPUCORES | bc`%
- Memory free (real) = `free -m | head -n 2 | tail -n 1 | awk {'print $4'}` Mb
- Memory free (cache) = `free -m | head -n 3 | tail -n 1 | awk {'print $3'}` Mb
- Swap in use = `free -m | tail -n 1 | awk {'print $3'}` Mb
- Disk space used = `df --total -h | tail -1 | awk '{ a = $3; b = $2; c = $5 } END { print c, "(", a, "/", b, ")" }'`
- Disk space available = `df --total -h | tail -1 | awk '{ a = $4; b = $2; c = $5 } END { print (100-c)"%", "(", a, "/", b, ")" }'`
" > /etc/motd.d/root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment