wildfire
Posts: 618
Joined: Sat Sep 03, 2016 10:39 am
Location: Dundee, Scotland

Communicating with other Pi's on network.

Sat Mar 25, 2017 5:24 am

Ok, plan is to have several Pi's on the same network all bar 1 headless. The headless Pi's are meant to run 24/7 though there may be situations when I have to shut all of them down.

Rather than VNC to them 1 by 1 it'd be great if the headed Pi (call him the Boss) could say to the headless (bairns) it's time for bed. The bairns should reply OK Boss going to sleep now.

If all goes as expected Boss then switches of, if not he should report which bairn is not responding.

An "are you OK?" program would be nice as well. The Pi's will have fixed IP's on the network, all connected wirelessly (3b's or 0W's).
E8 85 A2 64 C9 64 81 94 64 81 95 64 89 84 89 96 A3
Still NF Shirls

Ernst
Posts: 1334
Joined: Sat Feb 04, 2017 9:39 am
Location: Germany

Re: Communicating with other Pi's on network.

Sat Mar 25, 2017 7:01 am

Have you looked at ssh and arping ? The following script I use to shutdown a node (~ port) on a clusterhat (www.clusterhat.com).

Code: Select all

#!/bin/bash

PORT=$1
GATEWAY='192.168.0.254'

if [ X$PORT == 'X' ]
then
  echo port not specified
  exit 1
fi;

sudo ping -c 3 -q $GATEWAY > /dev/null
if [ $? -ne 0 ]
then
  echo default gateway $GATEWAY not responding
  exit 1
fi


if [[ $PORT == 'raspi3p1' || $PORT == 'raspi3p2' || $PORT == 'raspi3p3' || $PORT == 'raspi3p4' ]]
then
  sudo arping -c 1 -q $PORT 2> /dev/null
  if [ $? -ne 0 ]
  then
    echo $PORT not active
    exit
  fi
fi

if [[ $PORT == 'raspi3p1' || $PORT == 'raspi3p2' || $PORT == 'raspi3p3' || $PORT == 'raspi3p4' ]]
then
  ssh $PORT sudo shutdown 0 2> /dev/null
  if [ $? -ne 0 ]
  then
    echo Port $PORT failed
    exit 1
  fi

  while `sudo arping -c 1 -q $PORT 2> /dev/null`; do echo -n .; sleep 5; done
  echo -n \*;sleep 5;echo -n \*;sleep 5; echo -n ' ';
  clusterhat off ${PORT:(-2)}
else
  echo invalid port: $PORT
fi

exit 0
The road to insanity is paved with static ip addresses

wildfire
Posts: 618
Joined: Sat Sep 03, 2016 10:39 am
Location: Dundee, Scotland

Re: Communicating with other Pi's on network.

Sat Mar 25, 2017 11:39 am

Ernst wrote:Have you looked at ssh and arping ? The following script I use to shutdown a node (~ port) on a clusterhat (http://www.clusterhat.com).
Perfect, needs small amendments for my specific needs but I understand enough to make required changes.

Thanks Ernst. :D
E8 85 A2 64 C9 64 81 94 64 81 95 64 89 84 89 96 A3
Still NF Shirls

Return to “Beginners”