screen-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: reading an environment variable from screen [SOLVED]


From: Michael Grant
Subject: Re: reading an environment variable from screen [SOLVED]
Date: Thu, 17 Dec 2020 09:56:05 -0500

> In that case, this solution can be expanded a bit to do what you
> want. The basic idea would be:
> 1. On login, create a directory $HOME/.ssh/sockets/$TIME/ and put
>    a file setting the variables correctly in there (for example,
>    name the file $HOME/.ssh/sockets/$TIME/sshenv). In that case,
>    $TIME is what you get from "date +%s" (so don't login to the
>    same machine from two different sources in the same second to
>    avoid any trouble). At the same time, set a variable
>    "remove_on_logout" to "$HOME/.ssh/sockets/$TIME/"
> 2. In your .logout, put this command:
>    rm -fr "$remove_on_logout"
> 3. In your shell, set prompt_command or pre_cmd or similar to
>    contain something like
>    . $(ls -1 $HOME/.ssh/sockets/*/sshenv | tail -1)
> 
> This way, you will always have a working $SSH_AUTH_SOCK even
> though you login and logout time and again.

I don't think this is going to work.  The * will sort by time, so if
you log in first from your laptop, then from your desktop, then try to
ssh from your laptop, it's going to pick up the last one on the list
which will be from your desktop.

Ultimately, this seems to be the easiest and most concise way I found
to solve the problem based on Neal's -Q and msgwait suggestions:

Add this to a .bashrc or similar:

function fix_ssh_auth_sock() {
    screen -S $STY -X colon "msgwait 0\r"
    export SSH_AUTH_SOCK=`screen -S $STY -Q echo '$SSH_AUTH_SOCK\r'`
    screen -S $STY -X colon "msgwait 5\r"
}
export PROMPT_COMMAND=fix_ssh_auth_sock

No need to create anything special in /tmp.  No need to remove files
on logout.  No need for creating sym-links.  This just seems to work.
In zsh, use a precmd.  I don't know what the function syntax is in
zsh.

Thanks all!

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]