Discussion:
Set ip lan address /etc/environment
(too old to reply)
Maykel Franco via arch-general
2018-05-30 11:07:59 UTC
Permalink
Hi, I put this text in /etc/environment:

$ source /etc/environment

ip="$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d
' ' -f 1)"

$ echo $ip

192.168.0.33

Works fine, but when I reboot my archlinux:

$ echo $ip

$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)


What's happened?? Is necessary exec source /etc/environment after every reboot?

Thanks in advanced.
Mark . via arch-general
2018-05-30 11:11:54 UTC
Permalink
Why not put it in ~/.profile? Or if it needs to be system wide, in
/etc/profile.d/ip.sh?
Post by Maykel Franco via arch-general
$ source /etc/environment
ip="$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d
' ' -f 1)"
$ echo $ip
192.168.0.33
$ echo $ip
$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)
What's happened?? Is necessary exec source /etc/enviro
Ralph Corderoy
2018-05-30 11:20:05 UTC
Permalink
Hi Maykel,
Post by Maykel Franco via arch-general
$ source /etc/environment
ip="$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)"
https://wiki.archlinux.org/index.php/Environment_variables#Globally says
/etc/environment doesn't take code, just simple assignments.
Also see pam_env(8) and the rest of that wiki page.
--
Cheers, Ralph.
https://plus.google.com/+RalphCorderoy
Maykel Franco via arch-general
2018-05-30 11:31:44 UTC
Permalink
Post by Ralph Corderoy
Hi Maykel,
Post by Maykel Franco via arch-general
$ source /etc/environment
ip="$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)"
https://wiki.archlinux.org/index.php/Environment_variables#Globally says
/etc/environment doesn't take code, just simple assignments.
Also see pam_env(8) and the rest of that wiki page.
--
Cheers, Ralph.
https://plus.google.com/+RalphCorderoy
Thanks for your response but doesn't work

Put file /etc/profile.d/ip.sh with the content:

ip="$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d
' ' -f 1)"

Not work.

And I probe this:

/etc/security/pam_env.conf :

ip DEFAULT="" OVERRIDE="$(ifconfig | grep -A 1
'eth0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)"

And not working...
Mark . via arch-general
2018-05-30 11:33:06 UTC
Permalink
Perhaps head over to #archlinux on Freenode irc to get some more
interactive help…?
Post by Maykel Franco via arch-general
Post by Ralph Corderoy
Hi Maykel,
Post by Maykel Franco via arch-general
$ source /etc/environment
ip="$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)"
https://wiki.archlinux.org/index.php/Environment_variables#Globally says
/etc/environment doesn't take code, just simple assignments.
Also see pam_env(8) and the rest of that wiki page.
--
Cheers, Ralph.
https://plus.google.com/+RalphCorderoy
Thanks for your response but doesn't work
ip="$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)"
Not work.
ip DEFAULT="" OVERRIDE="$(ifconfig | grep -A 1
'eth0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)"
Ralph Corderoy
2018-05-30 12:17:26 UTC
Permalink
Hi Maykel,
Post by Maykel Franco via arch-general
ip="$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)"
To debug this kind of thing, e.g. to see if it even runs, intersperse
tee(1)s to files that can be inspected afterwards.

ip="$(ifconfig | tee /tmp/d.ifc | grep -A 1 'eth0' | tail -1 | tee ...
Post by Maykel Franco via arch-general
ip DEFAULT="" OVERRIDE="$(ifconfig | grep -A 1
I see nothing to suggest PAM supports sh's `$()' syntax, and wouldn't
expect it to.
--
Cheers, Ralph.
https://plus.google.com/+RalphCorderoy
Leonid Isaev via arch-general
2018-05-30 16:34:50 UTC
Permalink
Post by Maykel Franco via arch-general
$ source /etc/environment
ip="$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d
' ' -f 1)"
$ echo $ip
192.168.0.33
$ echo $ip
$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)
What's happened?? Is necessary exec source /etc/environment after every reboot?
Thanks in advanced.
/etc/environment is for PAM not shell, so it only allows ip=xxx.yyy.zzz.aaa .
Also, /etc/profile is for LOGIN shells, meaning that from scripts or when doing
scp(1) it won't be read. What exactly are you trying to achieve?

Cheers,
--
Leonid Isaev
Maykel Franco via arch-general
2018-05-31 09:32:31 UTC
Permalink
2018-05-30 18:34 GMT+02:00 Leonid Isaev via arch-general
Post by Leonid Isaev via arch-general
Post by Maykel Franco via arch-general
$ source /etc/environment
ip="$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d
' ' -f 1)"
$ echo $ip
192.168.0.33
$ echo $ip
$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)
What's happened?? Is necessary exec source /etc/environment after every reboot?
Thanks in advanced.
/etc/environment is for PAM not shell, so it only allows ip=xxx.yyy.zzz.aaa .
Also, /etc/profile is for LOGIN shells, meaning that from scripts or when doing
scp(1) it won't be read. What exactly are you trying to achieve?
Cheers,
--
Leonid Isaev
I need define variable called ip with current ip address machine...

And when reboot machine, the variable ip always has ip address.
Ralph Corderoy
2018-05-31 09:44:25 UTC
Permalink
Hi Maykel,
Post by Maykel Franco via arch-general
I need define variable called ip with current ip address machine...
And when reboot machine, the variable ip always has ip address.
Yes, I think we all figured that bit out. :-)
But why; what's going to be using that IP-address environment variable,
and when?
--
Cheers, Ralph.
https://plus.google.com/+RalphCorderoy
Leonid Isaev via arch-general
2018-05-31 10:01:16 UTC
Permalink
Post by Ralph Corderoy
Hi Maykel,
Post by Maykel Franco via arch-general
I need define variable called ip with current ip address machine...
And when reboot machine, the variable ip always has ip address.
Yes, I think we all figured that bit out. :-)
But why; what's going to be using that IP-address environment variable,
and when?
Indeed. Is it for consumption of users whose shell you don't know? Is it for
scripts, like cron jobs?

In the former case, see what is in /etc/shells, and drop a script to
/etc/profile.d, one for each shell. But that will be for login shells. In the
latter case, I am afraid you need to define it each time...

Finally, a bit of a puzzle, what are you going to do when the network goes
down, i.e. should the variable be unset or updated? In other words, how certain
are you that the IP address remains unchanged throughout the machine uptime?
--
Leonid Isaev
Maykel Franco via arch-general
2018-06-01 06:48:03 UTC
Permalink
2018-05-31 12:01 GMT+02:00 Leonid Isaev via arch-general
Post by Leonid Isaev via arch-general
Post by Ralph Corderoy
Hi Maykel,
Post by Maykel Franco via arch-general
I need define variable called ip with current ip address machine...
And when reboot machine, the variable ip always has ip address.
Yes, I think we all figured that bit out. :-)
But why; what's going to be using that IP-address environment variable,
and when?
Indeed. Is it for consumption of users whose shell you don't know? Is it for
scripts, like cron jobs?
In the former case, see what is in /etc/shells, and drop a script to
/etc/profile.d, one for each shell. But that will be for login shells. In the
latter case, I am afraid you need to define it each time...
Finally, a bit of a puzzle, what are you going to do when the network goes
down, i.e. should the variable be unset or updated? In other words, how certain
are you that the IP address remains unchanged throughout the machine uptime?
--
Leonid Isaev
I need this for docker. I have docker services in which I use
variables and I want to pass the always updated ip variable. If the
network goes, it is not a problem, it will always have the same fixed
static ip. But this way I leave docker generalized for any pc.
Leonid Isaev via arch-general
2018-06-05 00:13:19 UTC
Permalink
Post by Maykel Franco via arch-general
2018-05-31 12:01 GMT+02:00 Leonid Isaev via arch-general
Post by Leonid Isaev via arch-general
Post by Ralph Corderoy
Hi Maykel,
Post by Maykel Franco via arch-general
I need define variable called ip with current ip address machine...
And when reboot machine, the variable ip always has ip address.
Yes, I think we all figured that bit out. :-)
But why; what's going to be using that IP-address environment variable,
and when?
Indeed. Is it for consumption of users whose shell you don't know? Is it for
scripts, like cron jobs?
In the former case, see what is in /etc/shells, and drop a script to
/etc/profile.d, one for each shell. But that will be for login shells. In the
latter case, I am afraid you need to define it each time...
Finally, a bit of a puzzle, what are you going to do when the network goes
down, i.e. should the variable be unset or updated? In other words, how certain
are you that the IP address remains unchanged throughout the machine uptime?
--
Leonid Isaev
I need this for docker. I have docker services in which I use
variables and I want to pass the always updated ip variable. If the
network goes, it is not a problem, it will always have the same fixed
static ip. But this way I leave docker generalized for any pc.
I don't understand: "the always updated ip variable" implies that it can
change, no? In that case, storing it in a variable, won't track the changes. If
the IP is really static, it must exist in some file, like netctl profile...

Anyways, I think a better way is to write a shell function, like my_ip() that
simply prints the IP address to stdout...

Cheers,
--
Leonid Isaev
Loading...