Skip to content

Instantly share code, notes, and snippets.

@smalot
Last active July 24, 2020 03:58
Show Gist options
  • Save smalot/6920395 to your computer and use it in GitHub Desktop.
Save smalot/6920395 to your computer and use it in GitHub Desktop.
Script allowing stats on ssh login.
#!/bin/bash
#
# Server Status Script
# --------------------
#
# Install
# -------
#
# need dependencies :
# - bc
# - lsb_release
#
#
# crontab :
# */5 * * * * /usr/local/bin/systemstats.sh
#
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 = `lsb_release -d | cut -f2`
- Load Averages = `cat /proc/loadavg`
- System Uptime = `echo $UP`
- Platform Data = `uname -a`
- 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 -h / | awk '{ a = $4 } END { print a }'`
" > /etc/motd
# End of script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment