Created
May 24, 2017 10:03
-
-
Save hitesh83/04edbd5fbc1f0a8456dfe16df2d7943b to your computer and use it in GitHub Desktop.
Getting Dynamic IP from pi in mail
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/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" [email protected] < $NOWIPADDR | |
fi | |
else | |
curl $GETIPADDR > $NOWIPADDR | |
mail -s "ADD SUBJECT HERE" [email protected] < $NOWIPADDR | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment