Created
January 9, 2022 12:38
-
-
Save VojtaStruhar/6e0c5af3241d2e95a271bef93a6d0abc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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