Skip to content

Instantly share code, notes, and snippets.

@leshniak
Last active February 5, 2022 22:59
Show Gist options
  • Save leshniak/0a3571c216135c31808c8cb441cc3fbf to your computer and use it in GitHub Desktop.
Save leshniak/0a3571c216135c31808c8cb441cc3fbf to your computer and use it in GitHub Desktop.
Raspberry Pi MOTD, with TBW for Samsung SSDs (requires smartmontools) and WAN IP from DNS query (requires dig tool)
#!/bin/bash
UP_SECONDS=`/usr/bin/cut -d. -f1 /proc/uptime`
SECS=$(($UP_SECONDS % 60))
MINS=$(($UP_SECONDS / 60 % 60))
HOURS=$(($UP_SECONDS / 3600 % 24))
DAYS=$(($UP_SECONDS / 86400))
UPTIME=`printf "%d days, %02dh %02dm %02ds " "$DAYS" "$HOURS" "$MINS" "$SECS"`
PROCESSES=`ps ax | wc -l | tr -d " "`
MEM_INFO=`cat /proc/meminfo`
MEM_FREE=`echo "$MEM_INFO" | awk '/^MemFree/ {printf("%d", ($2 / 1024))}'`
MEM_TOTAL=`echo "$MEM_INFO" | awk '/^MemTotal/ {printf("%d", ($2 / 1024))}'`
CPU_TEMP_RAW=`cat /sys/class/thermal/thermal_zone0/temp`
CPU_TEMP=`printf "%0.1f" $(($CPU_TEMP_RAW/1000))`
SMART=`/usr/sbin/smartctl -A /dev/sda`
SSD_TEMP=`echo "$SMART" | awk '/^190/ {printf("%.1f", $10)}'`
SSD_TBW=`echo "$SMART" | awk '/^241/ {printf("%.2fTB (%d%% used)", ($10 * 512) / 1024^4, 100 - $4)}'`
WAN_IP=`/usr/bin/dig -4 +time=1 +tries=1 +noall +answer +short myip.opendns.com @resolver1.opendns.com 2> /dev/null || echo '?'`
# get the load averages
read ONE FIVE FIFTEEN REST < /proc/loadavg
echo -e "\033[0;32m
.~~. .~~. \033[0;37m`date +"%A, %-d %B %Y, %R"`\033[0;32m
'. \ ' ' / .' \033[0;37m`uname -srmo`\033[0;31m
.~ .~~~..~. \033[0;37m\033[0;31m
: .~.'~'.~. : \033[0;37mUptime.............: ${UPTIME}\033[0;31m
~ ( ) ( ) ~ \033[0;37mMemory.............: ${MEM_FREE}MB free, ${MEM_TOTAL}MB total\033[0;31m
( : '~'.~.'~' : ) \033[0;37mRunning Processes..: ${PROCESSES}\033[0;31m
~ .~ ( ) ~. ~ \033[0;37mLoad Averages......: ${ONE}, ${FIVE}, ${FIFTEEN}\033[0;31m
( : '~' : ) \033[0;37mPublic IPv4........: ${WAN_IP}\033[0;31m
'~ .~~~. ~' \033[0;37mTemperature........: CPU ${CPU_TEMP}°C, SSD ${SSD_TEMP}°C\033[0;31m
'~' \033[0;37mTotal Bytes Written: SSD ${SSD_TBW}\033[0m\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment