Skip to content

Instantly share code, notes, and snippets.

@mackuba
Created April 22, 2013 21:40
Show Gist options
  • Save mackuba/5438786 to your computer and use it in GitHub Desktop.
Save mackuba/5438786 to your computer and use it in GitHub Desktop.
Monitors external IP address using curlmyip.com and sends an email when it changes (should be run from cron)
#!/bin/bash
FILE="$HOME/ip-monitor.txt"
OLD_IP=`cat $FILE`
CURRENT_IP=`curl -s http://curlmyip.com`
EMAILS="my.address@gmail.com"
SUBJECT="IP address changed"
FROM="IP Address Bot <root@localhost>"
if [ "$CURRENT_IP" ]; then
if [ "$CURRENT_IP" != "$OLD_IP" ]; then
echo "New external IP address: $CURRENT_IP" | mail -s "$SUBJECT" -a "From: $FROM" $EMAILS
echo "$CURRENT_IP" > $FILE
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment