Environment variables
is there a $ variable that I can call and return the local IP address? I printenv and saw only one for REMOTEHOST
|
well there can be any number of local ip addresses... use ifconfig to pull out the one you want.
|
try this:
my_ip=$(/sbin/ifconfig eth0 | grep "inet addr" | cut -d : -f 2 | cut -d " " -f 1) echo $my_ip |
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. |
Wow..... thanks. Lemme try....
|
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. |
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.
|
Quote:
Jeremiah |
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. |
Code:
MY_IP=$(/sbin/ifconfig eth0 | grep "inet addr" | cut -d : -f 2 | cut -d " " -f 1) 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 |
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?
|
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 |
All times are GMT -5. The time now is 05:37 PM. |