Created
October 20, 2012 22:30
-
-
Save elchappo/3925055 to your computer and use it in GitHub Desktop.
IP update detection
This file contains 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 | |
NOW=$(date +"%m/%d/%Y") | |
LOG=${PWD}/"ip.log" | |
MAIL="/bin/mail" | |
# email subject | |
SUBJECT="Latest IP address" | |
# Email To ? | |
EMAIL="[email protected]" | |
# Email text/message | |
EMAILMESSAGE="/tmp/emailmessage.txt" | |
function ext-ip () { curl http://ipecho.net/plain; echo; } | |
#read old ip | |
NEWIP=$(ext-ip) | |
#check if log file is there | |
touch $LOG || exit | |
OLDIP=$(head -n 1 $LOG) | |
#if ip not updated skip | |
if [ "$NEWIP" != "$OLDIP" ] | |
then | |
echo "New IP detected" | |
echo $NEWIP > $LOG | |
#send email | |
echo "New IP is: $NEWIP"> $EMAILMESSAGE | |
echo "Date: "$NOW >>$EMAILMESSAGE | |
$MAIL -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE | |
else | |
echo "IP not updated" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment