ar51an / raspberrypi-motd

Dynamic Message Of The Day (MOTD) For Raspberry Pi
MIT License
62 stars 14 forks source link

Thank you #2

Closed aolszowka closed 1 year ago

aolszowka commented 1 year ago

Thank you for this project, and more importantly the excellent documentation you provided; using your scripts as a guide I modified them for my purposes to grab a few additional pieces of information and make the output a little closer to what you'd see in Ubuntu. I'm using a Raspberry Pi 1 for this so I can't use Ubuntu like I do on my other Pi Boxes and therefore do not have access to landscape-common (/usr/share/landscape/landscape-sysinfo.wrapper):

#!/bin/bash

# Adapted from https://github.com/ar51an/raspberrypi-motd

function color (){
  echo "\e[$1m$2\e[0m"
}

function sec2time (){
  local input=$1

  ((days=input/86400))
  ((input=input%86400))
  ((hours=input/3600))
  ((input=input%3600))
  ((mins=input/60))

  local daysPlural="s"
  local hoursPlural="s"
  local minsPlural="s"

  if [[ $days -eq 0 ||  $days -eq 1 ]]; then
    daysPlural=""
  fi
  if [[ $hours -eq 0 || $hours -eq 1 ]]; then
    hoursPlural=""
  fi
  if [[ $mins -eq 0 || $mins -eq 1 ]]; then
    minsPlural=""
  fi
  echo "$days day$daysPlural $hours hr$hoursPlural $mins min$minsPlural"
}
statsLabelColor="30;38;5;143"
infoColor="30;38;5;74"

# Stats
dateNow="$(date)"
systemload="$(awk '{print $1}' /proc/loadavg)"
diskUsage="$(df -h ~ | awk 'NR==2 { printf "%sB / %sB \\e[30;38;5;144m» Free: %sB\\e[0m",$3,$2,$4; }')"
swapUsage="$(free -h --si | awk 'NR==3 { printf "%sB / %sB \\e[30;38;5;144m» Free: %sB\\e[0m",$3,$2,$4; }')"
temperature="$(vcgencmd measure_temp | cut -c "6-9") C"
memoryStats="$(free -h --si | awk 'NR==2 { printf "%sB / %sB \\e[30;38;5;144m» Free: %sB\\e[0m",$3,$2,$4; }')"
processes="$(/bin/ls -d /proc/[0-9]* | wc -l)"
userCount="$(($(uptime | cut -d "," -f 2 | xargs | cut -d " " -f 1) + 1 ))" # Always seems to be off by one; just work around it
uptime="$(sec2time $(cut -d "." -f 1 /proc/uptime))"
ipAddr="$(hostname -I)"

# Print it out line by line
echo -e ""
echo -e "  System information as of $dateNow"
echo -e ""
echo -e "  $(color $statsLabelColor "System load:")  $(color $infoColor "$systemload")"
echo -e "  $(color $statsLabelColor "Usage of /:")   $(color $infoColor "$diskUsage")"
echo -e "  $(color $statsLabelColor "Memory usage:") $(color $infoColor "$memoryStats")"
echo -e "  $(color $statsLabelColor "Swap usage:")   $(color $infoColor "$swapUsage")"
echo -e "  $(color $statsLabelColor "Temperature:")  $(color $infoColor "$temperature")"
echo -e "  $(color $statsLabelColor "Processes:")    $(color $infoColor "$processes")"
echo -e "  $(color $statsLabelColor "IP Address:")   $(color $infoColor "$ipAddr")"
echo -e "  $(color $statsLabelColor "Users:")        $(color $infoColor "$userCount")"
echo -e "  $(color $statsLabelColor "Uptime:")       $(color $infoColor "$uptime")"

image

ar51an commented 1 year ago

You are welcome, appreciate your compliment. Glad it helped in creating your desired motd. Looks cool.