Created
May 18, 2020 05:29
-
-
Save SnoFox/ba4672d347dc77a3a8dbf75d10f0a468 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# Set to the fortune file you want to use, or empty string for no fortunes | |
fortune_file=holo | |
. $(dirname $0)/motd-commons | |
if [ $fancy -eq 1 ]; then | |
printf "Welcome to $(hostname).\n${F_RED}System load is high; simple MOTD will be used${F_RESET}\n" | |
exit 0 | |
fi | |
if [ -r /etc/banner ]; then | |
cat /etc/banner | |
elif [ $(which figlet) ]; then | |
figlet $(hostname -s) | |
fi | |
if [ ! -z $fortune_file ]; then | |
printf " -- %s\n" "$(/usr/games/fortune ${fortune_file})" | |
fi | |
echo | |
[ -r /etc/lsb-release ] && . /etc/lsb-release | |
os="$DISTRIB_ID $DISTRIB_RELEASE $DISTRIB_CODENAME" | |
if [ "$os" == " " ]; then | |
os=$(uname -o; uname -r; uname -m) | |
fi | |
printf "Welcome to %s, running %s (kernel %s).\n" "$(hostname)" "$os" "$(uname -r)" |
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/sh | |
. $(dirname $0)/motd-commons | |
echo | |
printf "System information as of %s\n\n" "$(date)" | |
if [ $fancy -eq 1 ]; then | |
printf "Top by CPU usage\n-----------------\n" | |
top -b -n1 | head -n17 | |
printf "\nTop by mem usage\n-----------------\n" | |
top -b -n1 -o %MEM | head -n17 | tail -n+7 | |
exit 0 | |
fi | |
load=$(cut -d' ' -f1-3 /proc/loadavg) | |
uptime=$(uptime -p|sed 's/^up //') | |
booted=$(date -d "`uptime -s` +"|tr -s ' ') | |
memory_usage=$(awk '/MemTotal:/ { total=$2 } /MemFree:/ { available=$2 } END { used=total-available; printf "%3.1f%%", used/total*100}' /proc/meminfo) | |
swap_usage=$(awk '/SwapTotal:/ { total=$2 } /SwapFree:/ { free=$2 } END { if (total=="0") { printf "No swap" } else { used=total-free; printf "%3.1f%%", used/total*100 }}' /proc/meminfo) | |
time=$(uptime | grep -ohe 'up .*' | sed 's/,//g' | awk '{ printf $2" "$3 }') | |
printf "%-24s%s (%s)\n" "Online since:" "$booted" "$uptime" | |
printf "%-24s%s\n" "System load:" "$load" | |
printf "%s %-10s%s %s\n" "Memory Usage:" "$memory_usage" "Swap Usage:" "$swap_usage" |
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/sh | |
. $(dirname $0)/motd-commons | |
echo | |
if [ $fancy -eq 1 ]; then | |
exit 0 | |
fi | |
if [ $(which zpool) ]; then | |
zpool list -H -p -o name,size,alloc,health | awk ' | |
function human(x) { | |
s=" B KB MB GB TB EB PB YB ZB" | |
while (x>=1024 && length(s)>1) | |
{x/=1024; s=substr(s,4)} | |
s=substr(s,1,3) | |
xf=(s==" B ")?"%5d ":"%5.2f" | |
return sprintf( xf"%s", x, s) | |
} | |
{ | |
pool=$1; size=$2; alloc=$3; health=$4; | |
printf "Allocation of %-9s %s / %s (%2.1f%%)", pool":", human(alloc), human(size), alloc/size*100; | |
if(health != "ONLINE") { printf " \033[31m(UNHEALTHY)\033[0m" }; | |
print "" | |
}' | |
zfs list -H -p -d 1 -o name,avail,used,usedsnap -t filesystem,volume | grep '/' | awk ' | |
function human(x) { | |
s=" B KB MB GB TB EB PB YB ZB" | |
while (x>=1024 && length(s)>1) | |
{x/=1024; s=substr(s,4)} | |
s=substr(s,1,3) | |
xf=(s==" B ")?"%d":"%5.2f" | |
if(s==" B ") { s=" B" } | |
return sprintf( xf"%s", x, s) | |
} | |
{ | |
name=$1; avail=$2; used=$3; usedsnap=$4; | |
printf "Usage of %-14s %s / %s (%s of snapshots)\n", name":", human(used), human(avail), human(usedsnap); | |
}' | |
fi |
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/sh | |
. $(dirname $0)/motd-commons | |
if [ $fancy -eq 1 ]; then | |
exit | |
fi | |
echo | |
users=$(who|cut -d' ' -f1|sort|uniq -c|sort -nr|awk 'BEGIN {out=""; comma="false"} {out=out (comma == "false" ? comma=true : ", ") $2 " (" $1 " time" ($1 > 1 ? "s" : "")")"} END {print out}') | |
if [ -z "$users" ]; then | |
users="Just you" | |
fi | |
printf "Users logged in: %s\n" "$users" |
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/sh | |
echo |
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
F_RED="\e[31m" | |
F_RESET="\e[0m" | |
fancy_math="$(cut -f1 -d' ' /proc/loadavg) > $(nproc)" | |
fancy=$(echo $fancy_math | bc -l) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Throw it all into /etc/update-motd.d/ on Debian-based machines for fancy motd
Dependencies: bc, awk, grep, sort, uniq, top, sed, date, uname
Optional: zfs, fortune, figlet, lsb-release
Updates will not be provided; this is v1 of something from a private repo combined with some junk I wrote when I was a wee baby Linux user