What is common between environments in a shell terminal session?

I have a custom shell script that runs every time a user is supposed to log in or identify a user, they put it in /etc/profile.d and performed some basic operations with env variables. I recently added some code so that if the screen works, it will connect to it again without requiring me to enter anything. However, there are some problems. If I log in as root and su with another user, the code runs a second time. Is there a variable that I can set when the code is run for the first time that will prevent the code from being run the second time?

I was thinking of writing something to disk, but then I do not want the code to not run if I start a new terminal session. Here is the code. First, he tries to try again - if he is unsuccessful because he is already connected (as it may be in an intermittent session), he will "take" the session back.

screen -r if [ -z "$STY" ]; then exec screen -dR fi 

Ultimately, this error does not allow me to replace the user with another user, because as soon as I do this, he captures the screen session and returns me to where I started. Pretty frustrating

+4
source share
2 answers

The $ {PPID} of the shell that you get when you are su will be the su command. Thus, the conclusion

  ps -o command = $ PPID 

will start with the letters su , so check this out.

+1
source

I think you can get this right if you read the following entry (and the person for your favorite shell) Question about user vs profile

0
source

Source: https://habr.com/ru/post/1304028/


All Articles