Last active
July 24, 2020 03:58
-
-
Save smalot/6920395 to your computer and use it in GitHub Desktop.
Script allowing stats on ssh login.
This file contains hidden or 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 | |
# | |
# 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