raspberry pi utilities – rpinfo

rpinfo (or rpinfo.sh) is a Bash script that I’ve written over time to print out key statistics of my various Raspberry Pi systems. And when I say various, I mean various. Since 2013 I’ve slowly accumulated various versions of the Raspberry Pi, including several Raspberry Pi Zeroes, to the point where I now have over a dozen of the little critters sitting around and doing things.

The script will look for and if found, query certain applications I care about. Except for calling the external tools to get their versions, I’ve tried to keep everything within Bash itself, especially using Bash’s built-in string and array features. Of course it doesn’t always turn out that way. The use of cat (concatenate and print files), tr (translate characters), sed (stream editor) and grep (globally search a regular expression and print) is so deeply engrained in the way I write scripts due to decades of use.

Looking at the screen capture above, there are a few interesting items to call out. At the very top is the name of the board including revision. This is followed by a block of statistics that includes the CPU type and the OS Description. At the very bottom is the filesystem size. Yes, I have a 128GB Sandisk micro SDXC card installed. It’s an Extreme and I’ve been slowly picking them up from my local Costco because Costco has been selling them in a two pack for US $30. They’re high performance with lots of elbow room. With a 128GB card in the Raspberry Pi 4 I have a computer that exceeds my desk side Dell tower I was using in the early to mid 2000s.

The way I use this script is to have a copy on every Raspberry Pi I have in the house. It’s just a quick way to catalogue the critical features I need. It’s my hope you find this useful, either in whole or some of its parts.

#!/usr/bin/env bash## Copyright (c) 2019 William H. Beebe, Jr.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.## ------------------------------------------------------------------------------## Simple Bash script to display information about any Raspberry Pi board in# inventory.## Note that for the version string we have to use tr to substitute the ending# null byte for a newline, or else a warning about null is emitted by the# latest versions of Bash.#model=$(cat /proc/device-tree/model | tr '\0' '\n')echoecho " ${model}"echomemTotal=$(cat /proc/meminfo | grep MemTotal | sed 's/:/ :/' | sed 's/ */ /g')echo " ${memTotal}"# Look for the explicit processor/core type (i.e. 'Cortex-A53')#data=$(lscpu | grep 'Model name:')wordarray=(${data//:/ })echo " CPU Type : ${wordarray[2]}"# Look for the core count. Use wc (word count) to count lines (-l).#coreCount=$(cat /proc/cpuinfo | grep processor | wc -l)echo " Core Count : ${coreCount}"hardware=$(cat /proc/cpuinfo | grep Hardware | tr '\t' ' ')echo " ${hardware}"revision=$(cat /proc/cpuinfo | grep Revision | tr '\t' ' ')echo " ${revision}"echokernelRevision=$(uname -r)echo " Kernel Release: ${kernelRevision}"description=$(lsb_release --all 2>/dev/null | grep Description | tr '\t' ' ')echo " OS ${description}"echoecho " Tools"version=$(git --version)echo " Git: ${version}"echoecho " Languages Installed"golang='/usr/local/go/bin/go'if [ -e ${golang} ]thenversion=$(${golang} version)echo " Go: ${version}"elseecho " No Go found."firustlang="$HOME/.cargo/bin/rustc"if [ -e ${rustlang} ]thenversion=$(${rustlang} --version)echo " Rust: ${version}"elseecho " No Rust found."fi# Redirect stderr to stdout for Python 2 version, because# that's they way they did it, printing version string to# stderr...version=$(python -V 2>&1)echo " ${version}"version=$(python3 -V)echo " ${version}"version=$(pip3 -V)wordarray=(${version})echo " Pip ${wordarray[1]}"version=$(gcc --version)wordArray=(${version})echo " Gcc ${wordArray[3]}"echodf -kh .echo