Last active
January 12, 2018 16:29
-
-
Save wedi/c51c0888493cdc644ec86a601c457b09 to your computer and use it in GitHub Desktop.
MOTD system information
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/sh | |
# Uptime ---------------------------------------------------------------------- | |
upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)" | |
secs=$((${upSeconds}%60)) | |
mins=$((${upSeconds}/60%60)) | |
hours=$((${upSeconds}/3600%24)) | |
days=$((${upSeconds}/86400)) | |
uptime=`printf "%d days, %02dh %02dm %02ds" "$days" "$hours" "$mins" "$secs"` | |
# Users ----------------------------------------------------------------------- | |
users_logged_in=$(users | tr ' ' '\n' | sort | uniq -c | awk '{ print $2 " (" $1 ")" }' | paste -d ", " -s) | |
# Memory ---------------------------------------------------------------------- | |
mem_str=$(free -m | head -n2 | tail -n1 | awk '{ printf "%5d %5d %5d\n", $3, $4, $2 }') | |
mem=$(free -m | head -n2 | tail -n1 | awk '{ printf "%4d MB Used, %4d MB Free, %4d MB Total\n", $3, $4, $2 }') | |
# Swap ------------------------------------------------------------------------ | |
swap_str=$(free -m | tail -n1 | awk '{ printf "%6d %6d %6d\n", $3, $4, $2 }') | |
swap=$(free -m | tail -n1 | awk '{ printf "%4d MB Used, %4d MB Free, %4d MB Total\n", $3, $4, $2 }') | |
# CPU ------------------------------------------------------------------------- | |
load_avg_str=$(cat /proc/loadavg | awk '{ printf "%.2f, %.2f, %.2f\n", $1, $2, $3 }') | |
load_avg=$(cat /proc/loadavg | awk '{ printf "%.2f (1 Min.), %.2f (5 Min.), %.2f (15 Min.)\n", $1, $2, $3 }') | |
# HDD ------------------------------------------------------------------------- | |
hdd_str=$(df -h / | tail -n1 | awk '{ printf "%6d %6d %6d\n", $3, $4, $2 }') | |
hdd=$(df -h / | tail -n1 | awk '{ printf "%7s Used, %7s Free, %7s Total\n", $3, $4, $2 }') | |
disc_percent=$(df -h / | tail -n1 | awk '{ print $5 }') | |
# Network --------------------------------------------------------------------- | |
net_rx=$(echo "scale=1; $(cat /sys/class/net/ens3/statistics/rx_bytes)/1024/1024" | bc) | |
net_tx=$(echo "scale=1; $(cat /sys/class/net/ens3/statistics/tx_bytes)/1024/1024" | bc) | |
net=$(printf "%s MB RX, %s MB TX" $net_rx $net_tx) | |
ipv4=$(ifconfig ens3 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}') | |
ipv6=$(ifconfig ens3 | grep "inet6 addr" | grep "Global" | awk '{print $3}') | |
last_login_time=$(last | head -n1 | awk '{ printf "%s, %d. %s, %s Uhr\n", $4, $6, $5, $7 }') | |
last_login_from=$(last | head -n1 | awk '{ printf "%s from %s\n", $1, $3 }') | |
cat << eof | |
-- Network ------------------------------------- | |
Name: wilma.weise.cloud | |
Usage: ${net} | |
Public IPv4 Address: ${ipv4} | |
Public IPv6 Address: ${ipv6} | |
Last Login: ${last_login_time} | |
${last_login_from} | |
Logged in: ${users_logged_in} | |
-- System Usage -------------------------------- | |
Uptime: ${uptime} | |
Load: ${load_avg} | |
Memory: ${mem} | |
Swap: ${swap} | |
HDD: ${hdd} | |
-- System Info --------------------------------- | |
CPU: `cat /proc/cpuinfo | grep 'model name' | head -1 | cut -d':' -f2` | |
Distro: `lsb_release -s -d` with `uname -r` (`uname -m`) | |
eof | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment