What is common between environments within a shell terminal session?

Posted by Matt1776 on Stack Overflow See other posts from Stack Overflow or by Matt1776
Published on 2010-03-13T18:30:25Z Indexed on 2010/03/13 18:35 UTC
Read the original article Hit count: 145

Filed under:
|
|
|
|

I have a custom shell script that runs each time a user logs in or identity is assumed, its been placed in /etc/profile.d and performs some basic env variable operations. Recently I added some code so that if screen is running it will reattach it without needing me to type anything. There are some problems however. If I log-in as root, and su - to another user, the code runs a second time. Is there a variable I can set when the code runs the first time that will prevent a second run of the code?

I thought to write something to the disk but then I dont want to prevent the code from running if I begin a new terminal session. Here is the code in question. It first attempts to reattach - if unsuccessful because its already attached (as it might be on an interruped session) it will 'take' the session back.

screen -r

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

Ultimately this bug prevents me from substituting user to another user because as soon as I do so, it grabs the screen session and puts me right back where I started. Pretty frustrating

© Stack Overflow or respective owner

Related posts about ssh

Related posts about session