I'm setting up a web server that won't have a static global IP. It will be at my parents house and I won't be able to SSH into it when the global IP changes. The global IP will change every time router is restarted which happens like once a month.
I need a script that sends me an email every time the global IP changes. So I can update the DNS so my website will work again.
I don't know anything about scripts in Ubuntu, but I know the basics in Java and PHP.
Computer: Ubuntu 13.10 server, iMac G4 Globe.
Have you considered using dynamic DNS update script/tool?
e.g. ddclient available as Debian/Ubuntu package.
It can update your DNS zone OR update your dynamic DNS record (so you can ssh in) and execute custom script to send you email.
Based on the code from this answer I have modified and added a few more options for debugging.
I had to set up the email server and use
crontab -e
to get this to email me my current ip address. You will also need to make the script file executable and make sure your user has read and write permission to the folder you put the scripts in.You can write a simple script to run from the cron and daily at particular time.
Take the existing ip in a file and then run your if loop to check the new ip with the existing ip and if both the ip's remain same, it can skip sending mail. Otherwise, if there is a change in IP it should send mail with the new ip.
you can run the script hourly, daily, weekly.
I am using this to check my ip address once a day.
If you have a linux computer with static ip address somewhere I would say just rcp the file ~/myip over there.
If that is not the case you can always use a handy command line tool called sendEmail (not to be confused with sendmail). This tool makes it very easy to send an email with a one line command. http://caspian.dotconf.net/menu/Software/SendEmail/
You could write something along these lines:
A bit of an old thread but it comes up pretty high on the list when you Google search for how to monitor for external IP changes.
As an alternative option that might help you, I've written a python script designed to monitor for external IP address changes. It currently saves the "current" external IP address to a file and, when run, grabs a new IP address and then checks it against the old one. It is design to email you if a change is detected.
It's designed to run as a cronjob and does not run as a background daemon on its own.
Here's the link to the github repository: https://github.com/begleysm/ipwatch
Hopefully it helps!