Skip to content

Instantly share code, notes, and snippets.

@rberaldo
Last active December 15, 2015 10:39
Show Gist options
  • Save rberaldo/5246883 to your computer and use it in GitHub Desktop.
Save rberaldo/5246883 to your computer and use it in GitHub Desktop.
A small script I thought about writing in a dream.
#!/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
@rberaldo
Copy link
Author

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