LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-31-2002, 06:30 PM   #1
kdnt
LQ Newbie
 
Registered: Oct 2002
Posts: 7

Rep: Reputation: 0
Environment variables


is there a $ variable that I can call and return the local IP address? I printenv and saw only one for REMOTEHOST
 
Old 10-31-2002, 06:42 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975
well there can be any number of local ip addresses... use ifconfig to pull out the one you want.
 
Old 10-31-2002, 07:04 PM   #3
born4linux
Senior Member
 
Registered: Sep 2002
Location: Philippines
Distribution: Slackware, RHEL&variants, AIX, SuSE
Posts: 1,127

Rep: Reputation: 49
try this:

my_ip=$(/sbin/ifconfig eth0 | grep "inet addr" | cut -d : -f 2 | cut -d " " -f 1)
echo $my_ip
 
Old 10-31-2002, 07:33 PM   #4
kdnt
LQ Newbie
 
Registered: Oct 2002
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks but what I want to do is to add a little IP information
in the /etc/issue file in my situation which several servers
share a single monitor through a switcher, and all machines
have the same text mode login screen, confuses users
occasionally.
 
Old 10-31-2002, 07:35 PM   #5
kdnt
LQ Newbie
 
Registered: Oct 2002
Posts: 7

Original Poster
Rep: Reputation: 0
Wow..... thanks. Lemme try....
 
Old 10-31-2002, 08:02 PM   #6
kdnt
LQ Newbie
 
Registered: Oct 2002
Posts: 7

Original Poster
Rep: Reputation: 0
Yes it works. Thanks born4linux!

But, sorry for my ignorance.... where does the printenv output
sits? Want to hardcode the definition of my_ip into the system.
Thanks again.
 
Old 10-31-2002, 08:54 PM   #7
kdnt
LQ Newbie
 
Registered: Oct 2002
Posts: 7

Original Poster
Rep: Reputation: 0
and... upon adding that $my_ip to /etc/issue, what thing do i have to restart so the change takes effect without rebooting? Thanks big time once again in advance.
 
Old 10-31-2002, 09:17 PM   #8
jdc2048
Member
 
Registered: Jul 2002
Location: Ohio, USA
Distribution: Redhat, Gentoo, Solaris, HP-UX, etc...
Posts: 391

Rep: Reputation: 30
Quote:
Originally posted by kdnt
Yes it works. Thanks born4linux!

But, sorry for my ignorance.... where does the printenv output
sits? Want to hardcode the definition of my_ip into the system.
Thanks again.
The question is a little vague. If you are asking how to make the system IP an environment variable, then you could take the code that born4linux gave you and add it to your /etc/profile. Make sure to export the variable as well. Best practice is to make any env vars in all caps (i.e. MY_IP instead of my_ip).

Jeremiah
 
Old 10-31-2002, 10:53 PM   #9
kdnt
LQ Newbie
 
Registered: Oct 2002
Posts: 7

Original Poster
Rep: Reputation: 0
yes thanks jeremiah. "/etc/profile" is what I want. And how to make the changes effective without rebooting? I did all you
experts said, but upon loading up another terminal and establishing connection (I'm doing all in secureCRT and have root permission) the change didn't show up. And what does "export the variable" mean? Thanks again.
 
Old 11-01-2002, 01:31 AM   #10
jdc2048
Member
 
Registered: Jul 2002
Location: Ohio, USA
Distribution: Redhat, Gentoo, Solaris, HP-UX, etc...
Posts: 391

Rep: Reputation: 30
Code:
MY_IP=$(/sbin/ifconfig eth0 | grep "inet addr" | cut -d : -f 2 | cut -d " " -f 1)
export $MY_IP
Shown above is how you can export the variable. This is done to make it available to all logged in users.

To make the IP show up on the login screen, you would want to add the IP into the file /etc/issue. There is no need to reboot or restart anything. All future connections will read this file when they make the connection.

You won't be able to use the $MY_IP inside the /etc/issue file though, because the /etc/profile is not read until after login. Whereas the /etc/issue file is read before login.

Jeremiah
 
Old 11-01-2002, 02:49 AM   #11
kdnt
LQ Newbie
 
Registered: Oct 2002
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks but don't fully understand. I guess you know what I'm trying to accomplish. What's your advice? It can be or can not be done?
 
Old 11-01-2002, 08:19 AM   #12
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,353
Blog Entries: 55

Rep: Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541
Another way if your IP address is static, and you've got network access at boot and you only need it for/etc/issue you process it this way as well. Add this line to for instance to rc.local, (w/o outer quotes) after any other lines that change issue: "host $(hostname) | awk '{print "Our IP address is:", $4}' >> /etc/issue"
If your IP address changes often then you better to add the line to the script that runs after you re-establish your connection.

You could also try "host $(hostname) | awk '{print "MY_IP=",$4}' > /etc/.myip" and pick it up in profile using if [ -f "/etc/.myip" ]; then . /etc/.myip; else MY_IP="unknown"; fi

Last edited by unSpawn; 11-01-2002 at 08:21 AM.
 
  


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
Environment Variables - where do they go!?! iansoundz Linux - General 7 11-17-2005 02:27 AM
environment variables in c++ s3b0 Programming 6 08-27-2004 09:19 AM
when to use environment variables? mark_2811 Programming 2 02-23-2004 06:09 PM
environment variables kakridge Linux - Newbie 1 07-14-2003 06:25 PM
environment variables aethereal Linux - Newbie 7 12-19-2001 09:34 AM


All times are GMT -5. The time now is 11:56 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration