Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora 17/18 > Servers & Networking
FedoraForum Search

Forgot Password? Join Us!

Servers & Networking Discuss any Fedora server problems and Networking issues such as dhcp, IP numbers, wlan, modems, etc.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 2nd December 2009, 01:41 AM
BECKConfused Offline
Registered User
 
Join Date: Mar 2009
Posts: 12
linuxfedorafirefox
Automatically Send E-mail Containing IP Address

Greetings!

I have several computers at work running Fedora 12. From time to time I need to remotely connect to them, usually via ssh. Each computer is assigned an IP number automatically upon startup, however due to circumstances beyond my control they are not recognized by host name by the domain server. Therefore I require the IP addresses in order to connect rather than the host names. I have no way at present to rectify this situation.

When there is a reboot, I am not always guaranteed that the IP address will be the same as before, although in practice this is usually the case. If the IP address is changed and I am logging on remotely, I am unable to connect! I can't know the number until I am again physically sitting at the computer.

As a solution, I would like each computer to e-mail me its IP address each time it boots. My first attempt was to run a script at the end of /etc/rc.d/rc.local that runs ifconfig and places the output into a file. This file is then sent to my address using sendmail. The script works fine, but I note that the output from ifconfig at this boot stage does not contain an IP address! Obviously, it is being assigned later on in the startup process. Either that or the command ifconfig does not work the same at this stage as it does once I am logged in. I require somebody with more expertise than I to comment on that.

Finally then, my question is, at what point in the startup process is an IP address assigned and the output from ifconfig would contain this address? Is there a more appropriate place rather than rc.local in which I should run my script? Is there a more appropriate command rather than ifconfig that ought to be used instead?

Thank you for your assistance with this, and I look forward to hearing your solutions to my problem.

---------- Post added at 05:41 PM CST ---------- Previous post was at 05:30 PM CST ----------

Let me show you my attempted solution in more detail in case you're interested. The script is called .SendIP.bash and is located in my home directory. Here's what it looks like (with some censoring to protect me from public ridicule):


#!/bin/sh
# This script will send ifconfig information to my e-mail account.
# This allows me to have the latest IP address assigned to this computer.
cd /home/MyUserName
hostname > .IPmessage
date >> .IPmessage
ifconfig eth0 >> .IPmessage
sendmail -f$HOSTNAME MyAddress@MyCompany.com < .IPmessage


In /etc/rc.d/rc.local I have added the following the lines to the end of the file:

...
# The following sends the assigned IP address to my e-mail account:
/home/MyUserName/.SendIP.bash


As I stated above, the output from ifconfig does not contain the IP address when my script is called from rc.local. Your assistance with determining when and from where to run the script would be greatly appreciated.
Reply With Quote
  #2  
Old 2nd December 2009, 01:59 AM
marcrblevins's Avatar
marcrblevins Offline
Registered User
 
Join Date: Jun 2006
Location: Texas
Age: 42
Posts: 4,168
linuxfedorafirefox
Instead of hostname, use:
Code:
ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'
Credits:
http://www.cyberciti.biz/faq/how-to-...splay-ip-only/

---------- Post added at 05:59 PM CST ---------- Previous post was at 05:58 PM CST ----------

BeckConfused, welcome to Fedora Forum!

You could have got on your router and look at its DHCP Client list.
Reply With Quote
  #3  
Old 2nd December 2009, 05:49 PM
BECKConfused Offline
Registered User
 
Join Date: Mar 2009
Posts: 12
linuxfedorafirefox
I Still Require Help

marcblevins: Thank you for your response.

And thanks for your modified command - its output is certainly much more succinct than mine and I'll be sure to use it once I've figured the rest out. You will note that I do use ifconfig in my script, however I am also collecting more verbose output such as hostname, date, etc.

However, I am still stuck with the same problem that I stated before. When ifconfig is called from rc.local during the startup process, its output does not contain the IP address at all. Your command, which of course works just fine from the command prompt, yields an empty string when called through rc.local.

Here is the full output from "ifconfig eth0" when called from my script .SendIP.bash, which is called at the end of rc.local during startup:

eth0 Link encap:Ethernet HWaddr 00:13:72:A0:76:6B
inet6 addr: fe80::213:72ff:fea0:766b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
Interrupt:16

Here is the output from "ifconfig eth0" when called from the command prompt (sorry, I thought it best to mask out the actual IP numbers as [IP]):

eth0 Link encap:Ethernet HWaddr 00:18:8B:1FE:04
inet addr:[IP] Bcast:[IP] Mask:255.255.255.128
inet6 addr: fe80::218:8bff:fe1f:ce04/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1993 errors:0 dropped:0 overruns:0 frame:0
TX packets:1834 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:706712 (690.1 KiB) TX bytes:257756 (251.7 KiB)
Interrupt:16

As you can see the latter case contains the IP address as well as the "inet addr" string that you search on in your command. The former case does not have this line.

I would certainly appreciate some suggestions from you and/or others on where and when to call my script during the startup process so that the IP address has been assigned and will be available through the ifconfig command (or any other command) to be e-mailed to me.

Thanks again for your help.
Reply With Quote
  #4  
Old 3rd December 2009, 02:31 AM
marcrblevins's Avatar
marcrblevins Offline
Registered User
 
Join Date: Jun 2006
Location: Texas
Age: 42
Posts: 4,168
linuxfedorafirefox
Oh, sorry about that.
Throw it in your /etc/cron.houry directory for now. You will get 24 e-mails a day per server. Or throw it in your /etc/cron.daily directory and get one e-mail a day per servers.
Reply With Quote
  #5  
Old 3rd December 2009, 04:45 PM
BECKConfused Offline
Registered User
 
Join Date: Mar 2009
Posts: 12
linuxfedorafirefox
That Solution Will Work

That would certainly work. I could probably tolerate a daily e-mail, but hourly is out of the question! Then again, perhaps I could set up a process to e-mail my manager and anonymous message every minute ...

One last question, and then I think I'll be done with this thread. Where would I look, perhaps in the Fedora documentation or elsewhere, for a description of the boot and startup process and chain of events? Specifically, I'd like to have a resource that details the sequence of files run and actions performed when the computer first boots up and the OS launches. I realize that there are a multitude of layers, but for my own education I'd like to see what happens under the hood. Does anyone know of a good place to start reading up on this?

Thanks again for your help.

I've been enjoying learning about and, hopefully, becoming more competent with Linux over the past year or so, but the most enjoyable part has been seeing just how helpful the Linux community has been in answering questions and providing help.
Reply With Quote
  #6  
Old 4th December 2009, 11:12 AM
amfpg Offline
Registered User
 
Join Date: May 2008
Posts: 84
windows_7firefox
Quote:
Originally Posted by BECKConfused View Post
That would certainly work. I could probably tolerate a daily e-mail, but hourly is out of the question! Then again, perhaps I could set up a process to e-mail my manager and anonymous message every minute ...

One last question, and then I think I'll be done with this thread. Where would I look, perhaps in the Fedora documentation or elsewhere, for a description of the boot and startup process and chain of events? Specifically, I'd like to have a resource that details the sequence of files run and actions performed when the computer first boots up and the OS launches. I realize that there are a multitude of layers, but for my own education I'd like to see what happens under the hood. Does anyone know of a good place to start reading up on this?

Thanks again for your help.

I've been enjoying learning about and, hopefully, becoming more competent with Linux over the past year or so, but the most enjoyable part has been seeing just how helpful the Linux community has been in answering questions and providing help.
look here

http://docs.fedoraproject.org/ and http://www.redhat.com/docs/
Reply With Quote
  #7  
Old 5th December 2009, 07:41 PM
lensman3 Offline
Registered User
 
Join Date: Dec 2009
Location: Centennial, Colorado USA
Posts: 128
linuxfedorafirefox
I don't think your network is up when you query ifconfig in rc.local script.

Pop the shell script into background with a sleep of about 2 minutes and see if that works. That should allow the network to boot.

Also, if your using NetworkConfig, I think it won't bring the network up (get an assigned IP address from your DHCP server) until the host tries to get something off the network. You might throw a "ping google.com" at the firont your script. Use googles IP numbers so that a DNS name does have to be resolved. Or ping your providers default gateway.

I have had the same problem, but I have traced my problem to the network driver not being ready to process network commands. Sometimes it works and sometimes it doesn't.

Hope this helps.

---------- Post added at 12:41 PM CST ---------- Previous post was at 12:38 PM CST ----------

Use the -s option on sendmail to put the ipaddress in the subject. That way you don't have to open the email. (The really, really, really lazy way)!!!
Reply With Quote
  #8  
Old 6th December 2009, 04:51 AM
scott32746 Offline
Registered User
 
Join Date: Jun 2007
Location: Lake Mary, Florida
Age: 48
Posts: 1,082
windows_xp_2003firefox
Hello,
You could do something like
Add to /etc/rc.local
sh /home/user/ipsend.sh &

vi ipsend.sh

#!/bin/bash


#sleep 3 mins
/bin/sleep 180

#Fedora Time Server 0.fedora.pool.ntp.org (207.171.7.152)
FTS="207.171.7.152"
IP=`/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`

/bin/ping -w 1 $FTS > /dev/null
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
/bin/echo "HOST: `hostname`" > /tmp/IPaddress
/bin/echo "IPADDRESS: $IP" >> /tmp/IPaddress
/bin/mail -s "$IP for `hostname`" user@company.com < /tmp/IPaddress
fi


If you add the wait to /etc/rc.local you get your login prompt after the sleep time completes

Last edited by scott32746; 6th December 2009 at 05:01 AM.
Reply With Quote
  #9  
Old 7th December 2009, 02:46 AM
lensman3 Offline
Registered User
 
Join Date: Dec 2009
Location: Centennial, Colorado USA
Posts: 128
linuxfedorafirefox
I use the following code on my firewall to make sure that the link doesn't go down. If it does go down then the script tries to reset the connection. I call it "keepalive.sh" on my firewall. There might be some code snippets that would work in your case. Such as if the ping doesn't come back then it tries to restart the IP connection. The internet side is on eth1 and I query the dhclient-eth1.pid to see if a IP number has been registered.

I have this in a cron than fires every minute. The my ISP gateway machine (which I just noticed is wrong here). There is one gotcha that I have it with this. Everytime this run, it starts a new process. If the Ethernet downstream is really hosed you can use up your process table and you will have to reboot. You have to reboot because there are no processes available to log in on.

This script was modified from the days of dialup connections and kept the ppp timers happy that somebody was using the connection.

The reason I added this was it kept my link alive, ALL THE TIME, to my provider. That way my IP address wouldn't be assigned to somebody else.


#!/bin/sh

if [ -f /var/run/dhclient-eth1.pid ] ; then
ping -c4 -l3 67.165.192.1 2>&1 | grep "0 received" > /dev/null && \
{ /sbin/ifdown eth1 > /dev/null; sleep 2; /sbin/ifup eth1; }
else
/sbin/ifdown eth1;
sleep 2;
/sbin/ifup eth1;
fi

Last edited by lensman3; 7th December 2009 at 02:51 AM. Reason: Added ALL THE TIME
Reply With Quote
  #10  
Old 7th December 2009, 02:55 AM
jpollard Offline
Registered User
 
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,105
linuxfedorafirefox
You could also try sending the script to batch from the rc.local script. That way the job won't be run until
after cron is up and running, which should be the last thing done. It would also only send the E-mail
once.
Reply With Quote
  #11  
Old 7th December 2009, 10:44 PM
BECKConfused Offline
Registered User
 
Join Date: Mar 2009
Posts: 12
linuxfedorafirefox
Thanks so much for the great solutions - just what I was asking for. I will put something together and give it a try.
Reply With Quote
Reply

Tags
ip address, rc.local, sendmail, startup

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Spam Assassin - IMAP, Fetch Mail Send Mail` polc1410 Servers & Networking 3 12th December 2005 12:26 PM
Evolution how send/receive mail and join to the mail lists bravo_elf Using Fedora 5 3rd August 2005 01:10 PM


Current GMT-time: 04:47 (Friday, 24-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat