I have a Raspberry Pi that I’m using in different environments. The easiest way to use the Pi is by just connecting power and network and use SSH, but when theres no screen, it’s not always easy to know the IP address of my Pi.
To make life easier for myself i have put the following lines in a start.sh script and added it to my crontab with the @reboot option. This will make crontab run this script every time the Pi has been rebooted (or shut down)
#!/bin/sh
sleep 30
echo “My IP is: $(ip addr | grep global | awk -F ‘ ‘ ‘{print $2}’)” | mail -s “Raspi reporting in…” someone@somewhere.org
The script will put in a 30 seconds delay to allow the Pi to pickup an address and then mail it for my mail address. Remember to make sure that your Pi is able to send mails, otherwise this will not work.
This will most likely ensure that i will get a mail with the IP address of my Pi, and I am ready to login with SSH.