Last active
December 15, 2015 10:39
-
-
Save rberaldo/5246883 to your computer and use it in GitHub Desktop.
A small script I thought about writing in a dream.
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 | |
IP=$(curl canihazip.com/s/ 2> /dev/null) | |
IP_FILE="/tmp/ip.txt " | |
if [ ! -f $IP_FILE ] | |
then | |
# If $IP_FILE doesn't exist, create one and mail me. | |
echo $IP > $IP_FILE | |
echo -e "A new /tmp/ip.txt file was created @ cookie.\n\ | |
Your current IP is $IP" | mail -s "IP report" rberaldo@cabaladada.org | |
exit 0 | |
else | |
# If it exists, compare to current. | |
OLD_IP=$(cat $IP_FILE) | |
if [ "$OLD_IP" == "$IP" ] | |
then | |
exit 0 | |
else | |
echo $IP > $IP_FILE | |
echo -e "Your IP has been updated.\n\ | |
Your current IP is $IP" | mail -s "IP report" rberaldo@cabaladada.org | |
exit 0 | |
fi | |
fi |
I just updated the gist. I now have a Raspberry Pi, so I no longer need to ssh into devio.us to send the email. I'm using sSMTP to send the email but ideally I want to set up a mail server on the RPi.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I run this script hourly, every 23rd minute, using cronie.