Im trying to write a script or prog (newbie needs help desperatly!)
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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!
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?
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.
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.
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) ...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.