LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 12: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, 05: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, 11:32 AM   #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, 11:44 AM   #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, 01:54 PM   #5
neo77777
LQ Addict
 
Registered: Dec 2001
Location: Brooklyn, NY
Distribution: *NIX
Posts: 3,704

Rep: Reputation: 56
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, 10: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, 01:56 AM   #7
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
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, 08: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, 08: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, 03:54 PM   #10
neo77777
LQ Addict
 
Registered: Dec 2001
Location: Brooklyn, NY
Distribution: *NIX
Posts: 3,704

Rep: Reputation: 56
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 03:58 PM.
 
Old 08-07-2002, 04: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, 06:32 PM   #12
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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 06:37 PM.
 
Old 08-07-2002, 10: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-07-2002, 11:13 PM   #14
neo77777
LQ Addict
 
Registered: Dec 2001
Location: Brooklyn, NY
Distribution: *NIX
Posts: 3,704

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

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:33 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