LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 07-11-2006, 12:00 PM   #1
scherfistv
LQ Newbie
 
Registered: Jul 2006
Posts: 4

Rep: Reputation: 0
Question Send email when TCP/IP address changes


Hi everyone, I'm looking a way to intercept the trigger/event when my server's IP address have changed to send me an email informing me that the new IP address is:....
Any suggestions would be appreciated. [solutions with dyndns.org I'm not interesed, I would like something with script,...]
 
Old 07-11-2006, 12:15 PM   #2
benjithegreat98
Senior Member
 
Registered: Dec 2003
Location: Shelbyville, TN, USA
Distribution: Fedora Core, CentOS
Posts: 1,019

Rep: Reputation: 45
Here is something I did a while ago. I haven't used it in a while. It looks like you'll have to create a directory called /etc/ipcheck/ . Just put the checkip somewhere and create a cron job to run it however often you want. Then put the mailmessage in the /etc/ipcheck directory you created. Make sure both of the files are executable.

Here is the file checkip
Code:
#!/bin/bash
#

/sbin/ifconfig eth1|grep "inet addr" > /etc/ipcheck/ipcheck.tmp

diffout=`diff --brief /etc/ipcheck/ipcheck /etc/ipcheck/ipcheck.tmp | awk '{ print $1 }'`

if [ -z $diffout ]; then
  # if diffout is empty (files match)
  rm -f /etc/ipcheck/ipcheck.tmp
else
  rm -f /etc/ipcheck/ipcheck
  mv -f /etc/ipcheck/ipcheck.tmp /etc/ipcheck/ipcheck

  ipstring=`cat /etc/ipcheck/ipcheck | awk '{ print $2 }'`

  /etc/ipcheck/mailmessage YOUREMAIL@DOMAIN.TLD $ipstring
fi
Here is the file mailmessage
Code:
#!/bin/bash
#

mail -s "Your IP Address Has Changed!" $1 << EOF
This is your new IP is $2
EOF

Last edited by benjithegreat98; 07-11-2006 at 12:28 PM.
 
Old 07-11-2006, 02:49 PM   #3
scherfistv
LQ Newbie
 
Registered: Jul 2006
Posts: 4

Original Poster
Rep: Reputation: 0
Smile

Thanx mate, you are great!
 
Old 07-11-2006, 06:02 PM   #4
benjithegreat98
Senior Member
 
Registered: Dec 2003
Location: Shelbyville, TN, USA
Distribution: Fedora Core, CentOS
Posts: 1,019

Rep: Reputation: 45
No Prob! And I forgot to mention you will need some sort of MTA running (sendmail or the like) and don't forget to replace YOUREMAIL@DOMAIN.TLD with your actual email address.

Good Luck!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Send logs to email address bond00 Linux - Networking 1 03-28-2006 07:01 PM
Send root mail to email address GUIPenguin Linux - General 1 03-01-2005 08:16 PM
send mail to external email address hamish Linux - Networking 8 12-10-2004 10:17 AM
how to send logs (etc.) to email address??? win32sux Slackware 7 08-26-2004 01:48 PM
Allowing an IP to send email using my email server... culprit Linux - Networking 7 09-09-2003 01:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 06:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration