LinuxQuestions.org
Visit Jeremy's Blog.
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 02-07-2007, 01:18 AM   #1
kbrajesh
LQ Newbie
 
Registered: Jan 2007
Posts: 3

Rep: Reputation: 0
Script to check IP address and send to an email


Is there a script/package which can check the external IP on regular basis and send the changes to an email?
 
Old 02-07-2007, 02:19 AM   #2
Notwerk
Member
 
Registered: Apr 2005
Location: Jordan
Distribution: Debian (Sarge), Ubuntu (6.06)
Posts: 271

Rep: Reputation: 31
This will check the current IP of the interface you sepcify and if it has changed will store it in a log file which can only be read by root. You can run it every 5 minutes in a crontab

Code:
#!/bin/sh

PATHIFCONFIG=/sbin/ifconfig
PATHCURRENTIP=/var/log/ipinfo/ip
IFACE=ppp0                # Specify the device you wish to monitor here
umask 177                 # Only root can read the log file

CURRENTIP=`$PATHIFCONFIG -a|grep -A 1 $IFACE|grep inet|awk '{print $2}' | awk -F: '{print $2}'`

grep $CURRENTIP $PATHCURRENTIP 1>/dev/null 2>&1

if [ $? -ne 0 ];
then
  CURRENTIP=`$PATHIFCONFIG -a|grep -A 1 $IFACE|grep inet|awk '{print  $2}' |awk -F: '{print $2}'`
  echo "$CURRENTIP" > $PATHCURRENTIP
fi
You can hack it a little to have it email the log file if it has changed.

Cheers

Last edited by Notwerk; 02-07-2007 at 02:21 AM.
 
Old 02-08-2007, 01:36 AM   #3
kbrajesh
LQ Newbie
 
Registered: Jan 2007
Posts: 3

Original Poster
Rep: Reputation: 0
Thank you for your quick reply .. I am new to linux and i dont have indepth knowledge . what i need is to get all the ip address of a machine daily basis.. line i need to get a mail at 9.30 AM or 10.00 AM everyday. Can you suggest a better method or tell me how can i send the output of the command ifconfig over mail.
 
Old 02-08-2007, 02:26 AM   #4
Notwerk
Member
 
Registered: Apr 2005
Location: Jordan
Distribution: Debian (Sarge), Ubuntu (6.06)
Posts: 271

Rep: Reputation: 31
You can pipe the output of the shell script to something like

Code:
#!/bin/sh
(
 echo "To: [ur_email_address]"
 echo "From: system <root>"
 echo "Subject: List of IPs"
 echo

[Script goes here]

) 2>&1 | /usr/lib/sendmail -t
exit 0
If course you'll need sendmail running and if the email address you're sending to isn't a local address you'll need to configure sendmail.

Do google around and check that man pages, too
 
Old 02-08-2007, 03:13 AM   #5
kbrajesh
LQ Newbie
 
Registered: Jan 2007
Posts: 3

Original Poster
Rep: Reputation: 0
once again thanks you for ur reply .. i got his script from one of the site.. but it is not working for me .. can u plz go through it


#!/bin/sh

FILE2=`echo "/fwlog/ifconfig.txt"`

touch /fwlog/ifconfig.txt
ifconfig eth0 | grep inet | awk -F: '{print $2}' | sed 's/Bcast//' > /fwlog/ifconfig.txt
mv -f /fwlog/ifconfig.txt $FILE2

cat $FILE2 | mail -s"IP address, ifconfig" xxxxx@xxxxxxxx.com



Rajesh
 
  


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
Script to send email... bfloeagle Linux - General 5 10-13-2009 10:20 AM
how to check that the email server is being used by someone to send spam ? kkeith Linux - Newbie 2 09-07-2006 06:37 AM
How to send an email within a script??? johnsanty Programming 19 09-02-2006 12:43 PM
Write a script to send an email from bash kpelczar Linux - Software 5 02-09-2005 04:19 PM
script to send email message meluser Programming 2 03-26-2003 12:35 AM

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

All times are GMT -5. The time now is 05:46 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
Open Source Consulting | Domain Registration