Skip to content

Instantly share code, notes, and snippets.

@hitesh83
Created May 24, 2017 10:03
Show Gist options
  • Save hitesh83/04edbd5fbc1f0a8456dfe16df2d7943b to your computer and use it in GitHub Desktop.
Save hitesh83/04edbd5fbc1f0a8456dfe16df2d7943b to your computer and use it in GitHub Desktop.
Getting Dynamic IP from pi in mail
#!/bin/bash
NOWIPADDR="/home/pi/nowipaddr"
GETIPADDR="dig +short myip.opendns.com @resolver1.opendns.com"
LOG="/home/pi/ip.log"
timestamp=$( date +%T )
curDate=$( date +"%m-%d-%y" )
if [ -f $NOWIPADDR ]; then
if [[ `$GETIPADDR` = $(< $NOWIPADDR) ]]; then
echo $curDate $timestamp " IP address check: " $(< $NOWIPADDR) >> $LOG
else
$GETIPADDR > $NOWIPADDR
mail -s "ADD SUBJECT HERE" ABCXYZ@gmail.com < $NOWIPADDR
fi
else
curl $GETIPADDR > $NOWIPADDR
mail -s "ADD SUBJECT HERE" ABCXYZ@gmail.com < $NOWIPADDR
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment