Score:0

Ubuntu: reading local user env variable in service

jp flag

I have a Linux service running on my ubuntu machine. in this machine, I need to read proxy setting environment variables ( like https_proxy, http_proxy, no_proxy, etc) values for the currently logged-in user.

when I am trying to read https_proxy from my service code, it is being printed as an empty string but when I am printing from the terminal the values are correct.

I think the service is not able to read it because it is running as root. Is there any way that can help in reading local user env variables from a service running with root privilege?

ChanganAuto avatar
us flag
What service and variables?
VikasPushkar avatar
jp flag
it is my own service and trying to read proxy env variables.
hr flag
*Users* don't have environments as such - they're a property of *processes*. You *might* be able to read a logged-in user's current environment by finding the PID of a process in their session then reading `/proc/<PID>/environ`, perhaps using `sudo -u <user>` to provide read access.
waltinator avatar
it flag
Have your user write the variables and their values into a file whenever you change them (automate this). Have your service read this file. Use `/run/local_env`, perhaps?
VikasPushkar avatar
jp flag
@steeldriver the process file at /proc/<pID>/environ does not have http_proxy/https_proxy/no_proxy ... am i missing something here?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.