Skip to content

Instantly share code, notes, and snippets.

@VojtaStruhar
Created January 9, 2022 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VojtaStruhar/6e0c5af3241d2e95a271bef93a6d0abc to your computer and use it in GitHub Desktop.
Save VojtaStruhar/6e0c5af3241d2e95a271bef93a6d0abc to your computer and use it in GitHub Desktop.
#!/bin/sh
# This scipt was created to simplify connecting to my Rasberry Pi 4
# via ssh. Be sure to set the MAC addresses and username accordingly!
DEVICES=$(arp -an)
parse_ip() {
RPI_ADDRESS=$(echo $DEVICES | grep $1 | \
awk -F '(' '{print $2}' | awk -F ')' '{print $1}')
}
# try ethernet address
parse_ip "e4:5f:1:xx:xx:xx"
if [ -z "$RPI_ADDRESS" ]
then
# try wifi address
parse_ip "e4:5f:1:xx:xx:xx"
if [ -z "$RPI_ADDRESS" ]
then
echo "Raspberry not found on this network!" >&2
exit 1
fi
fi
# We got raspberry address!
ssh "pi@$RPI_ADDRESS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment