Making a Raspberry Pi inventory (HPR Show 2496)

Dave Morriss

Table of Contents

Introduction

I have a number of Raspberry Pis – possibly too many – and I sometimes lose track of which is which, what model, size, name, address each one is. I wanted to be able to keep an inventory of them all, and to this end I wrote myself a little script that can be run on any Pi which will report useful information about it.

Every Pi has a unique serial number. Actually it’s randomly generated so there may be a few collisions but it’s close to unique! It also contains a revision number which encodes various items of information about it such as release date, model, PCB revision and memory. My script decodes this revision number for you based on a published table.

I run a Wikimedia instance on a Pi and have used this script to record details of my Pis there as well as what they are being used for and any planned projects. I now feel more organised!

Script

The script is called what_pi and uses Bash. The master copy is available on my GitLab repository or can be downloaded from HPR (or archive.org if you are reading these notes there). It is a work in progress and contains various notes pointing out possible shortcomings.

The script is listed below, but I will be brief in my description of its features in this episode.

The process of identifying important features like the revision, release date and model of the Pi is achieved by searching a table of data. The table originates from the website http://elinux.org/RPi_HardwareHistory and has just been copied and pasted into this script. Whenever new Pis are released and the website is updated it will be necessary to refresh this table.

If you do this make sure that the tab characters used in this table are preserved since they are used as the field delimiter.

The searching of the table and display of results is performed using Awk, with a program that is stored in a temporary file and run on lines 163-181.

The script tries to check that it is running on a Pi in the code on lines 97-102. This works for me, but may not be universal.

Lines 107-109 contain commands that create temporary files and set up a mechanism to delete them using the trap command. The function cleanup_temp is used to delete the files, and that is defined on lines 76-89. I plan to talk about trap a forthcoming episode on the way Bash works.

Any improvements to this script are welcome. Please submit a pull request to the GitLab repository.

Example output

This file (example_output.txt) can be downloaded if desired. See the Links section below.