Updating the Raspberry Pi Cluster without logging in to every Pi

The Raspberry Pi foundation have recently updated their Raspbian image. This brings bugfixes and upgrades to the Raspberry Pi. In this blogpost I share how you can run a command on your Raspberry Pi without logging in (this is mostly true although you still do “log in” just not in the typical way). This includes detailing how I have updated my Raspberry Pi Cluster quickly using this method.


Running a command on the Raspberry Pi without logging in

To run a single command on the Raspberry Pi you can use ssh similar to how you login. Instead of just entering in the name of the machine you can also add a command to run. For example you can run the below command.

ssh bunker-node4 "sudo apt-get update"

This will ssh into the machine bunker-node4 and then run the command passed to SSH. During the runtime of the command you will see the output as if you ran it after logging into the Raspberry Pi. Once the command has finished running you will be returned to your terminal.

In addition you can also run multiple commands by separating them with a semicolon (;) such as:

ssh bunker-node4 "whoami; pwd"

The above command will run whoami on the Raspberry Pi followed by pwd showing the output of both commands.

Updating all the nodes in my cluster

To update a Raspberry Pi to the new version you need to run apt-get update and apt-get dist-upgrade. I combined both these commands into a handy way to update each Raspberry Pi in turn.

ssh bunker-node4 "sudo apt-get update; sudo apt-get dist-upgrade; sudo reboot"

First this runs apt-get update and updates the package list. This gets the details of the newest packages and their required packages (dependencies). Once I have updated the package list I can then run apt-get dist-upgrade which upgrades the packages installed to the latest versions available.

Once this has updated the Raspberry Pi I then reboot it to reload all the services. I do this because any services that have been updated may need to be restarted to load the updated files. The easiest way of doing this and being sure that you are running the latest version of everything is by restarting the Raspberry Pi.

Many times after doing updates you  will not need to restart it but its something I can easily do to ensure everything is fully updated.



Add a Comment

Your email address will not be published. Required fields are marked *