I found a bunch of what seem complicated answers for how to do this. I made my own eventually just using bash and adding it to /etc/rc.local, turns out I didn’t need to have it in rc.local either, if I put it in /etc/network/if-up/ and made it executable.
#Send an email with the local IP
#sleep added to give me a wait to the process during boot and before remove to give the #script some time to run. These may not be needed. Adjust as needed.
#grep -v added to trim out some extra info from the file
#date added so it would append a time stamp to file
ifconfig | grep inet | grep -v inet6 | grep -v 127.0.0.1 >> file.tmp | date >> file.tmp
#-s after mail gives me a subject line
echo “$(cat file.tmp)” | mail -s IPaddress <email@example.com>
I added this line to /etc/rc.local, but I was getting two copies of the email on boot up. So I deleted it.
If I wanted my external IP I could add a line like below. Maybe put a line in cron to run the script every so often and get this info at times other than when I boot the Pi or when renewing the IP.
dig +short myip.opendns.com @resolver1.opendns.com >> file.tmp
To get dig I had to add apt-get install dnsutils.