LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 03-19-2008, 01:27 PM   #1
kponenation
Member
 
Registered: Jul 2004
Location: New Orleans, Louisiana
Distribution: Slackware 10.1
Posts: 142

Rep: Reputation: 15
IP address script


Hi,

I have a script that sends me an email of the ip address that is currently used. The script runs perfectly when the pc is up and running. I would like to run it when it boots up so I don't have to run it manually.
I've tried calling the script from /etc/rc.local and update-rc.d defaults. But I would get an email with blank IP address. I'm guessing it's because the box doesn't have an IP assigned to it when the script gets run.
I would like to know where I need to call my script so that ifconfig will return the IP address.
Thanks in advance.

James
 
Old 03-19-2008, 01:49 PM   #2
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
Quote:
Originally Posted by kponenation View Post
Hi,

I have a script that sends me an email of the ip address that is currently used. The script runs perfectly when the pc is up and running. I would like to run it when it boots up so I don't have to run it manually.
I've tried calling the script from /etc/rc.local and update-rc.d defaults. But I would get an email with blank IP address. I'm guessing it's because the box doesn't have an IP assigned to it when the script gets run.
I would like to know where I need to call my script so that ifconfig will return the IP address.
Thanks in advance.

James
if it's running in rc.local, the network should already be configured (being that rc.local is supposed to run after everything else).

If you want it to run at boot time, a slightly more proper way of doing it would be to put your script in /etc/init.d, then link to that script in the correct rcX.d directory (corresponding to your runlevel) with an S99 prefixed to the link name, i.e. S99myscript would be a link to /etc/init.d/myscript.

That said, it *should* work in rc.local. Are you sure paths are correct? It's possible a path var has not been set for the user that runs rc.local scripts (especially for things like /sbin or /usr/local/bin), so include full paths to all programs, i.e. "/sbin/ifconfig" rather than just "ifconfig".

lastly, you could put this in a cron script for your user that compares the output of ifconfig to some file & sends a mail when it changes, though that's kinda kludgey.
 
Old 03-19-2008, 02:04 PM   #3
kponenation
Member
 
Registered: Jul 2004
Location: New Orleans, Louisiana
Distribution: Slackware 10.1
Posts: 142

Original Poster
Rep: Reputation: 15
Thanks for the reply.
Since I've tried doing rc.local and links in rcX.d before posting the question, I went and used full paths to the commands that I used in the script.
It still doesn't work.

Last edited by kponenation; 03-19-2008 at 02:09 PM.
 
Old 03-19-2008, 02:30 PM   #4
kponenation
Member
 
Registered: Jul 2004
Location: New Orleans, Louisiana
Distribution: Slackware 10.1
Posts: 142

Original Poster
Rep: Reputation: 15
I just rebooted my PC after putting /sbin/ifconfig > /root/test in /etc/rc.local
and this is what was in /etc/test
eth0 Link encap:Ethernet HWaddr 00:19:B9:2D:E5:1C
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:11 errors:0 dropped:0 overruns:0 frame:0
TX packets:1 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:704 (704.0 b) TX bytes:94 (94.0 b)
Interrupt:16

No IP address...
What is going on???
 
  


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
script to get IP address of client pc semenick Linux - Networking 2 05-19-2006 03:36 PM
Re-using IP address in Script possible? crazygyhrous Linux - Networking 1 01-03-2006 05:00 PM
Change IP address via script ricky_ds Red Hat 2 01-04-2005 10:34 AM
creating a script to ask for a new IP address stellarmarine1 Linux - General 5 09-12-2004 08:08 PM
Bash Script: Getting IP address fr0st Programming 3 01-14-2004 06:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

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