I'm using DNSExit on my Ubuntu server (Natty 11.04) and have installed the ipUpdate rpm file and did an apt-get install for chkconfig to enable the ipUpdate.
I'd like to get an email whenever the IP address changes, so that I can SSH into the box using PuTTY (because I can't unless I know the current IP address).
The current IP address is stored in /tmp/dnsexit-ip.txt
, and I'd like to, whenever that file changes, to mail the contents of that file and the contents of /var/log/dnsexit.log
(which contains a history of the IP changes) to my email address.
How can I accomplish this task? I'm thinking that a cronjob will be the solution, but I'm not sure how to do this.
Prerequisites
Install sendEmail. It's a lightweight, command line SMTP email client. We'll use it to send emails from a script, using a Gmail account.
Create the script
Create a file named "ip-notify.sh" somewhere, for example in a "Scripts" directory in your home folder; make it executable, and open it up for editing.
Insert the following text in the file:
Once that's done, save and close the file.
Run the script periodically
We'll run this script every two minutes. Open up your crontab.
Add the following line to the bottom of the file:
You're done!
If all goes well, you should now get email updates when the IP address of your machine changes.
If you have a mail installed (I use postfix ... i.e. sudo apt-get install postfix) you can run a bash script in cron every 5 minutes.
The script uses 'stat' to check if the file changed in the last five minutes (300 seconds) if so the $diff variable will equal 1.
Some thing like this should work: