How to search for the sessions that have a certain environment variable set?


 
Thread Tools Search this Thread
Operating Systems Solaris How to search for the sessions that have a certain environment variable set?
# 1  
Old 09-30-2015
How to search for the sessions that have a certain environment variable set?

Hi all,

In Solaris 10, is there a way to search for the sessions that have a certain environment variable set?
# 2  
Old 09-30-2015
Does Solaris 10 have the /proc file system?
This works on linux:
Code:
sudo grep "TERM=linux" /proc/*/environ
Binary file /proc/1258/environ matches
Binary file /proc/1378/environ matches
Binary file /proc/1380/environ matches
Binary file /proc/1396/environ matches
Binary file /proc/1397/environ matches
Binary file /proc/1420/environ matches
Binary file /proc/1/environ matches
Binary file /proc/966/environ matches
Binary file /proc/self/environ matches
Binary file /proc/thread-self/environ matches

# 3  
Old 09-30-2015
Try
Code:
env

or
Code:
 cat ~.profile

or
Code:
/etc/default

# 4  
Old 09-30-2015
Quote:
Originally Posted by ejianu
In Solaris 10, is there a way to search for the sessions that have a certain environment variable set?
If by sessions you mean processes, this should be what you look for (replace VARIABLE by the name of the variable you are interested in):

Code:
for i in /proc/*; do
    pargs -e $i | grep VARIABLE= && ps -f -p $(basename $i)
done 2>/dev/null

Do it as root if you need to search processes you do not own.
# 5  
Old 10-01-2015
All,

Thanks for your suggestions. I did a test with the DISPLAY variable, I have set it in my session and I get to see it when i use env, however when I look for it with pargs -e it's not there.

I'm looking to find the PID of the session that uses a certain value for the DISPLAY variable, so I need to search after the value of the variable also.
# 6  
Old 10-01-2015
Have you set it in a shell? Then you need to export it.
Code:
bash$ export FOO=bar
bash$ pargs -e $$ | grep FOO=
envp[7]: FOO=bar

and is also found with jlliagre's method.
# 7  
Old 10-05-2015
I have exported the DISPLAY variable but for some reason it doesn't show up.

Code:
user@machine:/home/user>env
_=/usr/bin/env
SSH_TTY=/dev/pts/1
PATH=/usr/local/bin:/usr/bin:/bin
EDITOR=vi
LOGNAME=user
MAIL=/usr/mail/user
HOSTNAME=machine
USER=user
DISPLAY=10.5.205.232:236
SHELL=/usr/bin/ksh
HOME=/home/user
SSH_CONNECTION=129.121.221.47 53939 10.13.22.201 22
SSH_CLIENT=129.121.221.47 53939 22
TERM=xterm
PWD=/home/user
TZ=US/Central
ENV=/home/user/.kshrc
user@machine:/home/user>pargs -e $$
2925:   -ksh
envp[0]: USER=user
envp[1]: LOGNAME=user
envp[2]: HOME=/home/user
envp[3]: PATH=/usr/bin:/bin
envp[4]: MAIL=/var/mail//user
envp[5]: SHELL=/usr/bin/ksh
envp[6]: TZ=US/Central
envp[7]: SSH_CLIENT=129.121.221.47 53939 22
envp[8]: SSH_CONNECTION=129.121.221.47 53939 10.13.22.201 22
envp[9]: SSH_TTY=/dev/pts/1
envp[10]: TERM=xterm

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

What will be the effect of environment variable, when mulitple sessions are opened by same login?

Hello, What will be the effect of environment variable, when mulitple sessions are opened by same login? Following code snippet is part of a shell script. Environment : HP-UX B.11.31 U ia64 For Example EXECUTION_DIR=`pwd`/ EXECUTION_DIR_RT=${EXECUTION_DIR}RT/ export... (4 Replies)
Discussion started by: Siva SQL
4 Replies

2. Shell Programming and Scripting

Help needed with shell script to search and replace a set of strings among the set of files

Hi, I am looking for a shell script which serves the below purpose. Please find below the algorithm for the same and any help on this would be highly appreciated. 1)set of strings need to be replaced among set of files(directory may contain different types of files) 2)It should search for... (10 Replies)
Discussion started by: Amulya
10 Replies

3. Shell Programming and Scripting

Set Environment variable from another file

Hi, i have the following env variable. currently i am exporting variable in the same script file. but i need this is in a text file and the scripts need to export this variable from the text file. can you please suggest me. is it possible. export... (6 Replies)
Discussion started by: rsivasan
6 Replies

4. UNIX for Dummies Questions & Answers

ORACLE_HOME environment variable not set!

hi, i am new to perl: os : Linux i wrote simple perl script to select from table i am getting this error and how to set ORACLE_HOME environment variable : script: #!usr/bin/perl use DBI; use Mail::Sendmail; #use Date::Calc; use MIME::QuotedPrint; use HTML::Entities; use POSIX... (2 Replies)
Discussion started by: prakash.gr
2 Replies

5. Solaris

set environment variable?

I am working with solaris 9 sunBlade150 Box. I Installed a program, need to set the environment variable so that when the executable is entered,it finds the path to the executable. The documentation for the software says: Set the appropriate environment variable: Connect to server failed;... (8 Replies)
Discussion started by: smartgupta
8 Replies

6. Linux

How do i set environment variable

Hi, I am quite new to Linux. And I have doubt how to set new environment variable with value to a C executable. Let say I have a environment variable $Hack ; I would like to load a value for this variable; so that when the C executable is executed, the $Hack would set the variable value. ... (4 Replies)
Discussion started by: ahjiefreak
4 Replies

7. Shell Programming and Scripting

problem in getting the path of environment variable set in bashrc in my shell script

hi all i have joined new to the group. i have set an variable in my bashrc file. .bashrc PROGHOME=/home/braf/braf/prog export PROGHOME but while using it in my shell script its path is not taken and i had to explicitly give the export command to set the path. in my script... (8 Replies)
Discussion started by: krithika
8 Replies

8. UNIX for Advanced & Expert Users

how to set the environment variable at run time

hi, I have one environment variable like path in my system.But in my program i need to change that path .suppose it has a value "config" now i need to chage it as "config1" or something else.i need to use that variable for complete project.It means at first it will use the old path but after... (4 Replies)
Discussion started by: sada@123
4 Replies

9. UNIX for Advanced & Expert Users

set environment variable?

Installed a program, need to set the system up so that when the executable is entered, it finds the path to the executable. In Windows, set under system properties, advanced, environmental variables. How do I do this with Unix? Specifically using Solaris 9. I have tried: env... (3 Replies)
Discussion started by: kohoutek
3 Replies

10. UNIX for Advanced & Expert Users

How does the PATH and MANPATH environment variable get set?

Hi, How does the PATH and MANPATH environment variable get set? I want to add "/opt/SUNWspro/bin" to the search path for all the users. Where can I access this variable. I know in my home directory, depend on which shell I use, there are files such as .profile and .cshrc which I can edit to... (3 Replies)
Discussion started by: vtran4270
3 Replies
Login or Register to Ask a Question