[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: reading an environment variable from screen
From: |
Thomas Köhler |
Subject: |
Re: reading an environment variable from screen |
Date: |
Wed, 16 Dec 2020 18:08:56 +0100 |
User-agent: |
Mutt/1.10.1 (2018-07-13) |
Hi Michael,
On Wed, Dec 16, 2020 at 03:08:45PM +0000, Michael Grant <mgrant@grant.org>
wrote:
> When I reattach to screen, the SSH_AUTH_SOCK is wrong.
>
> I often ssh in and run screen simultaneously on a laptop and desktop. So I
> can’t use the trick of symlinking something to /tmp/ssh-xxxxxxxxxx.
>
> Is there some way to interrogate screen to tell me what the contents of an
> environment variable are?
>
> Running this in a shell inside of screen:
>
> screen -S $STY -X colon 'exec |echo $SSH_AUTH_SOCK\r'
>
> gives me the info I’m looking for, but it pushes it out to the display. I’m
> so close! How can I capture this output?
>
> My goal here is to create a sort of ssh/scp pre-command as a shell alias that
> probes screen each time and sets the SSH_AUTH_SOCK variable correctly.
I solved this whole issue as follows:
- during login, my zshrc runs this code:
touch $HOME/.ssh/agent_var ; chmod 600 $HOME/.ssh/agent_var
echo "export SSH_AGENT_PID=$SSH_AGENT_PID" > $HOME/.ssh/agent_var
echo "export SSH_AUTH_SOCK=$SSH_AUTH_SOCK" >> $HOME/.ssh/agent_var
- in my session, zsh's precmd() (that would maybe be
prompt_command in bash) can now ". $HOME/.ssh/agent_var" so the
variables are always set to something that works.
- I actually almost never worry about $SSH_AUTH_SOCK again. Only
case where this fails would be in the situation that I
a) login to the machine and reattach screen
b) login to the same machine a second time and logout of this
second session
c) now this machine has $HOME/.ssh/agent_var setup wrongly.
d) Fix is to logout of the first session and login again, then
reattach screen
I only end up in such a situation when actually testing some
changes to my shell configuration that requires me to login
again, as I otherwise work from my existing screen session, so
it's not so bad.
Ciao,
Thomas
--
Thomas Köhler Email: jean-luc@picard.franken.de
<>< WWW: http://gott-gehabt.de
IRC: tkoehler Freenode: thkoehler
PGP public key available from Homepage!
- reading an environment variable from screen, Michael Grant, 2020/12/16
- Re: reading an environment variable from screen,
Thomas Köhler <=
- Re: reading an environment variable from screen, Neal Fultz, 2020/12/16
- Re: reading an environment variable from screen, Michael Grant, 2020/12/16
- Re: reading an environment variable from screen, Neal Fultz, 2020/12/16
- Re: reading an environment variable from screen, Thomas Köhler, 2020/12/17
- Re: reading an environment variable from screen [SOLVED], Michael Grant, 2020/12/17
- Re: reading an environment variable from screen [SOLVED], Michael Grant, 2020/12/17
- Re: reading an environment variable from screen [SOLVED], Michael Grant, 2020/12/17