HomeRaspberry Pi › Up & Down
Up | Down | Feedback

Up & Down

top↑

Up

Check which hosts on the LAN are online. Handy to keep track of your vast collection of Raspberry Pis. Run from a computer on the same LAN with Bash shell scripting support, like one running OS X or Linux, or Windows with Cygwin. Save as ~/bin/uppi:

#!/bin/bash

LIST="blue orange white cam"  # Hostnames that I want to check
DNS="192.168.1.254"           # Local DNS server (my modem/router)
SUF=".lan"                    # Standard domain name suffix set by the DNS server

OFF=
ERR=0
for RPI in $LIST; do
	ADDR=`dig @$DNS $RPI$SUF A +short`
	if [ -z "$ADDR" ]; then
		OFF="$OFF $RPI"      # List of offline hosts
		(( ERR += 1 ))       # Count offline hosts
	else
		echo "$RPI [$ADDR]"  # Echo online host and IPv4 address to stdout
	fi
done

[ -z "$OFF" ] || echo "Offline:$OFF" >&2  # Echo offline hosts to stderr
exit $ERR                     # Exit status is number of hosts that are offline

On Raspbian, you probably need to install the dnsutils package first, which provides dig:

sudo apt-get update && sudo apt-get install dnsutils
top↑

Down

Power down your vast collection of Raspberry Pis. Save as ~/bin/downpi:

#!/bin/sh

LIST="blue orange white cam"  # Hosts that I want to power down

for RPI in $LIST; do
	ssh -x $RPI 'sudo poweroff'     # Use option -x to avoid X11 forwarding
					# which might be set in ~/.ssh/config
done
exit 0
top↑

Feedback

Cheers, boos and questions via the Raspberry Pi Forum.