Re: [arch-general] Set ip lan address /etc/environment
On Fri, Jun 01, 2018 at 08:48:03AM +0200, Maykel Franco via arch-general wrote: > 2018-05-31 12:01 GMT+02:00 Leonid Isaev via arch-general > : > > On Thu, May 31, 2018 at 10:44:25AM +0100, Ralph Corderoy wrote: > >> Hi Maykel, > >> > >> > 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
Re: [arch-general] Set ip lan address /etc/environment
2018-05-31 12:01 GMT+02:00 Leonid Isaev via arch-general : > On Thu, May 31, 2018 at 10:44:25AM +0100, Ralph Corderoy wrote: >> Hi Maykel, >> >> > 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.
Re: [arch-general] Set ip lan address /etc/environment
On Thu, May 31, 2018 at 10:44:25AM +0100, Ralph Corderoy wrote: > Hi Maykel, > > > 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
Re: [arch-general] Set ip lan address /etc/environment
Hi Maykel, > 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
Re: [arch-general] Set ip lan address /etc/environment
2018-05-30 18:34 GMT+02:00 Leonid Isaev via arch-general : > On Wed, May 30, 2018 at 01:07:59PM +0200, Maykel Franco via arch-general > wrote: >> 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. > > /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.
Re: [arch-general] Set ip lan address /etc/environment
On Wed, May 30, 2018 at 01:07:59PM +0200, Maykel Franco via arch-general wrote: > 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. /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
Re: [arch-general] Set ip lan address /etc/environment
Hi Maykel, > 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)" 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 ... > /etc/security/pam_env.conf : > 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
Re: [arch-general] Set ip lan address /etc/environment
Perhaps head over to #archlinux on Freenode irc to get some more interactive help…? On 30/05/2018 13:31, Maykel Franco via arch-general wrote: > 2018-05-30 13:20 GMT+02:00 Ralph Corderoy : >> Hi Maykel, >> >>> $ 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...
Re: [arch-general] Set ip lan address /etc/environment
2018-05-30 13:20 GMT+02:00 Ralph Corderoy : > Hi Maykel, > >> $ 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...
Re: [arch-general] Set ip lan address /etc/environment
Hi Maykel, > $ 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
Re: [arch-general] Set ip lan address /etc/environment
Why not put it in ~/.profile? Or if it needs to be system wide, in /etc/profile.d/ip.sh? On 30/05/2018 13:07, Maykel Franco via arch-general wrote: > 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.