LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 08-03-2002, 01:29 AM   #1
bripage
Member
 
Registered: Jan 2002
Location: Moorpark
Distribution: SLACK 8!
Posts: 230

Rep: Reputation: 30
Unhappy Im trying to write a script or prog (newbie needs help desperatly!)


Im trying to write a script or a prog (which ever will do the job) that:

1) Will get my networks external ip address ( the IP that my isp is giving me for the time being).

2) mail or somehoe transport the ip address to possibly an email account.


Im doing this in becuase I need to know my IP address to run SSH/FTP conrtol from another network and the network inquestion has a dynamic WAN (internet) IP address. Were in the address is changed periodically be the ISP for some reason.



If this just isnt possible. Id like to know how I cn set it up to take a queue from a hyperlink on a website which will be strapped to the machine in question. Do you understand? If so please help me!
 
Old 08-03-2002, 06:25 AM   #2
webtoe
Member
 
Registered: Apr 2001
Location: Cambridge, England
Distribution: Slackware 10, Fedora Core 3, Mac OS X
Posts: 617

Rep: Reputation: 30
look on the forum on this website for this. They have loads of scripts for it if you search for it

www.linuxformat.co.uk

Alex
 
Old 08-03-2002, 12:32 PM   #3
sarin
Member
 
Registered: May 2001
Location: India, Kerala, Thrissur
Distribution: FC 7-10
Posts: 354
Blog Entries: 2

Rep: Reputation: 34
I think something like

/sbin/ifconfig > tmpfile
mail user@far.away.dom < tmpfile

should work?
--Sarin
 
Old 08-03-2002, 12:44 PM   #4
MartBrooks
Member
 
Registered: May 2002
Location: London
Distribution: Debian
Posts: 388

Rep: Reputation: 31
/sbin/ifconfig | mail foo@bah.com -s "my ip is...."

Regards
 
Old 08-03-2002, 02:54 PM   #5
neo77777
LQ Addict
 
Registered: Dec 2001
Location: Brooklyn, NY
Distribution: *NIX
Posts: 3,704

Rep: Reputation: 55
If you want to strip just IP from all the goop ifconfig offers
use this as a line in your script:
Code:
IP=`/sbin/ifconfig ppp0 | grep 'inet addr' | awk '{print $2}' | sed -e s/.*://`
just substitute ppp0 to correct interface - eth0, etc if you are not on dila-up or PPPoE DSL connection
 
Old 08-04-2002, 11:18 PM   #6
bripage
Member
 
Registered: Jan 2002
Location: Moorpark
Distribution: SLACK 8!
Posts: 230

Original Poster
Rep: Reputation: 30
now... how am i gonna get this to start on boot? Should I just make it a seperate file and have rc.inet2 load it on boot?
 
Old 08-05-2002, 02:56 AM   #7
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,539

Rep: Reputation: 149Reputation: 149
Just add it to rc.local. It starts after all other boot scripts and that's what you want, I think.
 
Old 08-06-2002, 09:30 PM   #8
bripage
Member
 
Registered: Jan 2002
Location: Moorpark
Distribution: SLACK 8!
Posts: 230

Original Poster
Rep: Reputation: 30
now... how am I going to for sure know that it will email to a non LAN machines email address? Lets say that I wanted to have it send the email containing the current IP address to brian@hotmail.com , how would I make sure that it does this?
 
Old 08-06-2002, 09:34 PM   #9
bripage
Member
 
Registered: Jan 2002
Location: Moorpark
Distribution: SLACK 8!
Posts: 230

Original Poster
Rep: Reputation: 30
Also, Id like to have the message time stamped in the email. Example message:

***Wolf88 Linux Server IP address update***
Current IP address at (the time it is) : blah.blah.blah.blah


And then send it to the desired address. How whould I get it to do that?
 
Old 08-07-2002, 04:54 PM   #10
neo77777
LQ Addict
 
Registered: Dec 2001
Location: Brooklyn, NY
Distribution: *NIX
Posts: 3,704

Rep: Reputation: 55
How about including echo statement in the script
echo "Current time is `date`"
so the whole thing can be a one liner

#!/bin/sh
echo "IP for `hostname` is ` /sbin/ifconfig ppp0 | grep 'inet addr' | awk '{print $2}' | sed -e s/.*://` current time `date`"

Last edited by neo77777; 08-07-2002 at 04:58 PM.
 
Old 08-07-2002, 05:11 PM   #11
bripage
Member
 
Registered: Jan 2002
Location: Moorpark
Distribution: SLACK 8!
Posts: 230

Original Poster
Rep: Reputation: 30
and does that include the mail to bripage@myemail.com function? If not, were does that come in? and will the machine do this automatically?
 
Old 08-07-2002, 07:32 PM   #12
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,699
Blog Entries: 54

Rep: Reputation: 2962Reputation: 2962Reputation: 2962Reputation: 2962Reputation: 2962Reputation: 2962Reputation: 2962Reputation: 2962Reputation: 2962Reputation: 2962Reputation: 2962
IMO you better execute the script from /etc/ppp/ip-up, because this script gets run each time the connection is established so it's the easiest way to be sure a) you got the nfo and b) it can be sent.

To snag Neo77777's work you would do
echo "IP for `hostname` is ` /sbin/ifconfig ppp0 | grep 'inet addr' | awk '{print $2}' | sed -e s/.*://` current time `date`" | mail -s "<insert subject here>" <insert email address here>

or like your example
echo "." | mail -s "***Wolf88 Linux Server IP:$(/sbin/ifconfig ppp0 | grep 'inet addr' | awk '{print $2}' | sed -e s/.*://) date:$(date +%m-%d-%y)***" <insert email address here>

*note the echo "." just keeps it from saying it's having an empty message body. If you get additional commandline crud just tack "2>&1 >/dev/null" (w/o quotes) onto the end.

Last edited by unSpawn; 08-07-2002 at 07:37 PM.
 
Old 08-07-2002, 11:31 PM   #13
bripage
Member
 
Registered: Jan 2002
Location: Moorpark
Distribution: SLACK 8!
Posts: 230

Original Poster
Rep: Reputation: 30
Ok now... I get were were goin with this. But, theres a problem. If Ihave it giving my the linux machines IP address, itll never change and always be 192.168.1.103 . I want to know how, or if at all possible, that I can get a hold of the external (the IP address the internet will see my network as having, usuall something like 64.173.128.105 or somtin) and then do the email thing to it.
 
Old 08-08-2002, 12:13 AM   #14
neo77777
LQ Addict
 
Registered: Dec 2001
Location: Brooklyn, NY
Distribution: *NIX
Posts: 3,704

Rep: Reputation: 55
run ifconfig to find what interface gets assigned external IP, then just in the IP command substitute ppp0 to correct inteface
 
Old 08-08-2002, 12:15 AM   #15
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,004
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Quote:
Originally posted by bripage
Ok now... I get were were goin with this. But, theres a problem. If Ihave it giving my the linux machines IP address, itll never change and always be 192.168.1.103 . I want to know how, or if at all possible, that I can get a hold of the external (the IP address the internet will see my network as having, usuall something like 64.173.128.105 or somtin) and then do the email thing to it.
*cough ... that's what /sbin/ifconfig ppp0 will give you...
for the local network it would be /sbin/ifconfig eth0
(assuming that you have ethernet and not something
more uncommon) ...
 
  


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
how to write a simple c prog to call a script RajRed Programming 1 10-05-2005 06:10 PM
how to write a simple c prog to call a script RajRed Linux - Software 1 10-05-2005 03:57 PM
Help a newbie write a script! Braveheart1980 Linux - Software 14 09-22-2004 07:40 AM
need a script desperatly... ooagentbender Linux - Software 8 11-06-2003 08:43 PM
C prog..except input ,write to textfile?? kato678 Programming 1 02-21-2002 02:09 AM


All times are GMT -5. The time now is 07:32 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration