LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Send email when TCP/IP address changes (https://www.linuxquestions.org/questions/linux-networking-3/send-email-when-tcp-ip-address-changes-462986/)

scherfistv 07-11-2006 11:00 AM

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,...]

benjithegreat98 07-11-2006 11:15 AM

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


scherfistv 07-11-2006 01:49 PM

Thanx mate, you are great! :D

benjithegreat98 07-11-2006 05:02 PM

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!


All times are GMT -5. The time now is 02:55 PM.