Skip to content

Instantly share code, notes, and snippets.

@wranders
Last active January 12, 2018 19:19
Show Gist options
  • Save wranders/935157515e7f3a4a88b5ad7747b18c79 to your computer and use it in GitHub Desktop.
Save wranders/935157515e7f3a4a88b5ad7747b18c79 to your computer and use it in GitHub Desktop.
CLI/SSH MOTD Showing System Info
#!/bin/sh
#
# 01-header - CLI/SSH MOTD
# Author: W Anders <https://github.com/wranders>
#
# Written for use with `update-motd` package on
# Ubuntu/Debian systems, but should work with any MOTD
# package using the bash shell.
# Ensure this file has execute permissions
# ( chmod +x /etc/update-motd.d/01-header )
#
# OS information is from `os-release`, part of the `systemd` package.
#
# Displays hardware information and a customizable message.
#
# Demo ASCII art if from
# Text to ASCII Art Generator (TAAG) <http://patorjk.com/software/taag/>
# Demo art font is `ANSI Shadow`.
#
OS_NAME=$(grep -w NAME /etc/os-release | cut -d'=' -f2 | sed -e 's/^"//' -e 's/"$//')
OS_VERSION=$(grep -w VERSION /etc/os-release | cut -d'=' -f2 | sed -e 's/^"//' -e 's/"$//')
OS_DETAILS=$(uname -mor | awk {'print $3" "$1" "$2'})
UPTIME=$(uptime -p | sed -e 's/^up //')
CPU_TYPE=$(cat /proc/cpuinfo | grep 'model name' | head -1 | cut -d':' -f2 | sed -e 's/^ //')
CPU_LOAD=$(cat /proc/loadavg | awk {'print $1 * 100'})
MEM_TOTAL=$(free -m | head -n 2 | tail -n 1 | awk {'print $2'})
MEM_FREE=$(free -m | head -n 2 | tail -n 1 | awk {'print $4'})
MEM_FREE_PERCENT=$(free -m | head -n 2 | tail -n 1 | awk {'printf( "%.2f", ($4 / $2) * 100);'})
MEM_USED=$(free -m | head -n 2 | tail -n 1 | awk {'print $3'})
MEM_USED_PERCENT=$(free -m | head -n 2 | tail -n 1 | awk {'printf( "%.2f", 100 - (($4 / $2) * 100));'})
SWAP_TOTAL=$(free -m | tail -n 1 | awk {'print $2'})
SWAP_FREE=$(free -m | tail -n 1 | awk {'print $4'})
SWAP_FREE_PERCENT=$(free -m | tail -n 1 | awk {'printf( "%.2f", ($4 / $2) * 100);'})
SWAP_USED=$(free -m | tail -n 1 | awk {'print $3'})
SWAP_USED_PERCENT=$(free -m | tail -n 1 | awk {'printf( "%.2f", 100 - (($4 / $2) * 100));'})
DISK_TOTAL=$(df -h / | tail -n 1 | awk {'print $2'})
DISK_FREE=$(df -h / | tail -n 1 | awk {'print $4'})
DISK_FREE_PERCENT=$(df / | tail -n 1 | awk {'printf( "%.2f", ($3 / $2) * 100);'})
DISK_USED=$(df -h / | tail -n 1 | awk {'print $3'})
DISK_USED_PERCENT=$(df / | tail -n 1 | awk {'printf( "%.2f", 100 - (($3 / $2) * 100));'})
cat << EOF
*********************************************************
$OS_NAME $OS_VERSION
($OS_DETAILS)
█████╗ ███████╗ ██████╗██╗██╗ █████╗ ██████╗ ████████╗
██╔══██╗██╔════╝██╔════╝██║██║ ██╔══██╗██╔══██╗╚══██╔══╝
███████║███████╗██║ ██║██║ ███████║██████╔╝ ██║
██╔══██║╚════██║██║ ██║██║ ██╔══██║██╔══██╗ ██║
██║ ██║███████║╚██████╗██║██║ ██║ ██║██║ ██║ ██║
╚═╝ ╚═╝╚══════╝ ╚═════╝╚═╝╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝
*********************************************************
### WARNING MESSAGE ###
### ###
### Doesn't have to be a warning, could be legal info ###
*********************************************************
Uptime: $UPTIME
CPU: $CPU_TYPE
Load: $CPU_LOAD %
Memory: $MEM_TOTAL M
Free: $MEM_FREE_PERCENT % ($MEM_FREE M)
Used: $MEM_USED_PERCENT % ($MEM_USED M)
Swap: $SWAP_TOTAL M
Free: $SWAP_FREE_PERCENT % ($SWAP_FREE M)
Used: $SWAP_USED_PERCENT % ($SWAP_USED M)
Disk: $DISK_TOTAL
Free: $DISK_FREE_PERCENT % ($DISK_FREE)
Used: $DISK_USED_PERCENT % ($DISK_USED)
*********************************************************
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment