I have two active RPi's. They both have the script: adxl345test.py

This script collects data from an accelerometer. I usually start the script on one RPi and then start the script on the other RPi. I run the scripts from both RPi's on one RPi. So that one RPi starts running both its own script and an external script from the other RPi.

I trigger the scripts on each RPi by writing sudo python adxl345test.py in the console and then pressing Enter. The clocks are synced with PTPd. The RPi's are networked.

I run both script through one command. Here it is:

pi@Sensor1:~ $ sudo python adxl345test.py & sshpass -p 'password' ssh pi@ip sudo python adxl345test.py

Using sshpass (sudo apt-get install sshpass) I managed to type the password directly into the command.

Now I want to stop recording data! Normally I would use Ctrl+C but that only works when running a single script on one RPi.

What I'm looking for is to stop the scripts by writing a single command in the console of one RPi. Precision isn't that important at the moment.

I was thinking maybe I could use the following command:

sudo killall python & sshpass -p 'password' ssh pi@ip sudo killall python --- edited WORKS!

This command does stop both RPi from collecting data. On one RPi everything is fine and the data is logged properly however on the other RPi it for some reason doesn't log any data at all even though it was supposed to.

I want to be able to stop both RPi's from collecting data after x seconds.

Turns out the script I was running lacked an important definition. So now the abovementioned killall commando works and the data is also properly kept.


First you may use SSH public key authentication to run your command one remote RPIs, it's very comfortable. You can do it with a simple ssh-copy-id pi@ip from your master RPI (Sensor1), I can help you in comments if you want to setup this.

You can use 'timeout' to run your script for a defined time as explained here.

About your killall, are you sure that the process had run? Try to get the PID of the process with pgrep -f adxl345test.py after launching your script and look if a pid is returned, then kill it with kill <PID> and look if you get your datas.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.