Re: reading an environment variable from screen [SOLVED]
Michael Grant <mgrant-q2t/[email protected]> Thu, 17 Dec 2020 09:56:05 -0500
| Newsgroups | gmane.comp.gnu.screen.user |
|---|---|
| Message-ID | <[email protected]> |
> 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!
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEDXVee01gWrPIdWPRwgRAue7sYQMFAl/bcYMACgkQwgRAue7s YQMwkQ//fd1/9MN3/N9gH3pXILJfq0vg2cU9JZcPD7xGWjwozCOa3kEexeySnIqm kEFky5ZnRBT/DamMkoKLUeNFn9O4sxeXGtgY5woBujoQQGkB3TWbfAKMu1YdIfTC vJljeOkuxx4l9jV07kScOjHiJ9eOTLwgUTuoa8afIh5tF3QvUs3yKI2X42CEYi0S Vw+COvdTQ8DJ8nFNOJixKAuluaPbIKW3Vh9s9IIkzUp+qwQeuKaQUeEVDnN6FF1C Rhi6014cz6AKwDovyMWnTVUvJjn4Ep9e5SXvABzDEkw2JFiCwmu6LzcDjzbsCEjp CDL2I4P2YM2C8Rvh4RTczYPDfANfTrQ++GdXfghQlEi0PSyreArtmXVJHrzjwqee QVFdewEvtynt7e98D6MAAtYsrme31GUsIahmQxoGT1nLJJvqEFJ7UGgnbrOdZYQ3 sin8GS7G/UMxS3QDwkcM/hI+vJRg/6b8sGMYuEtgaEGiXesNYR/UpwJ4OMEGyElw oC+gDmAcbzVYcCHGUeiOgpFrB+NAEtATkKsH4wSNoOT0v8f94aSyjbpdih30fS+p n3pvwN7wfV3SBmz5KgOUugKtcH0/QXSiA+U+N6vrBb1W9VfcF/1oCvcOzn4p7hyc 38/vCZLDaKr8pADehBixv/tAgZbGuYbL9/U6TGnREJQt/l3SZ1I= =6v0r -----END PGP SIGNATURE-----