Skip to content

Instantly share code, notes, and snippets.

@xpl01ter
Created November 15, 2021 02:37
Show Gist options
  • Save xpl01ter/c2565c28de5bc4f383c5351c479ec48d to your computer and use it in GitHub Desktop.
Save xpl01ter/c2565c28de5bc4f383c5351c479ec48d to your computer and use it in GitHub Desktop.
RaspberryPi MOTD
#!/bin/bash
clear
let upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)"
let secs=$((${upSeconds}%60))
let mins=$((${upSeconds}/60%60))
let hours=$((${upSeconds}/3600%24))
let days=$((${upSeconds}/86400))
UPTIME=`printf "%d days, %02dh%02dm%02ds" "$days" "$hours" "$mins" "$secs"`
# calculate rough CPU temperature:sudo
if [[ -f "/sys/class/thermal/thermal_zone0/temp" ]]; then
cpuTempC=$(($(cat /sys/class/thermal/thermal_zone0/temp)/1000))
fi
MEM=`free -m | awk 'NR==2 { printf "Total: %sMB, Used: %sMB, Free: %sMB",$2,$3,$4; }'`
DISK=`df -h ~ | awk 'NR==2 { printf "Total: %sB, Used: %sB, Free: %sB",$2,$3,$4; }'`
VAR_IP_INTERN="$(hostname -I)"
VAR_IP_EXTERN4="$(wget -q -O - http://ipv4.icanhazip.com/ | tail)"
# get the load averages
read one five fifteen rest < /proc/loadavg
DARKGREY="$(tput sgr0 ; tput bold ; tput setaf 0)"
RED="$(tput sgr0 ; tput setaf 1)"
GREEN="$(tput sgr0 ; tput setaf 2)"
YELLOW="$(tput sgr0 ; tput setaf 3)"
BLUE="$(tput sgr0 ; tput setaf 4)"
WHITE="$(tput sgr0 ; tput setaf 7)"
NC="$(tput sgr0)" # No Color
echo "${GREEN}
.~~. .~~. ${YELLOW}`hostname -f`${GREEN}
'. \ ' ' / .' ${YELLOW}`date +"%A, %e %B %Y, %H:%M:%S"`${RED}
.~ .~~~..~.
: .~.'~'.~. : ${WHITE}Uptime.............: ${WHITE}${UPTIME}${RED}
~ ( ) ( ) ~ ${WHITE}Memory.............: ${WHITE}${MEM}${RED}
( : '~'.~.'~' : ) ${WHITE}Disk usage.........: ${WHITE}${DISK}${RED}
~ .~ ( ) ~. ~ ${WHITE}Load Averages......: ${WHITE}${one}, ${five}, ${fifteen} (1, 5, 15 min)${RED}
( : '~' : ) ${WHITE}Running Processes..: ${WHITE}`ps ax | wc -l | tr -d " "`${RED}
'~ .~~~. ~' ${WHITE}Local IPs..........: ${WHITE}${VAR_IP_INTERN}${RED}
'~' ${WHITE}External IP........: ${WHITE}${VAR_IP_EXTERN4}${RED}
${WHITE}Temperature........: ${WHITE}$cpuTempC°C${RED}
${NC}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment