-
Notifications
You must be signed in to change notification settings - Fork 0
Description
With a lot of long-running GNU screen(1) sessions, it's not uncommon for them to outlive other applications that are not running in a screen session, or that were running in screen sessions that have since ended. When this happens it is sometimes necessary to update some of the exported environment variables in processes running in the long-running screen sessions to allow them to communicate with new instances of some of those other applications. Two obvious examples here are for updating existing screen(1) sessions with vars for X11 (DISPLAY) and/or ssh-agent(1) (SSH_AGENT_PID and SSH_AUTH_SOCK).
The screen-ls(1) tool helps automate this sort of thing, but it is still cumbersome to do it with any frequency. For example:
$ for sess in $(screen-ls); do
> echo &&
> echo working on: $sess &&
> screen -S "${sess}" -X setenv SSH_AGENT_PID SOME_PID_VALUE &&
> screen -S "${sess}" -X setenv SSH_AUTH_SOCK PATH_TO_SOME_SOCKET \
> || break;
> done
It would be nice if there were a tool that would allow for this thing to be expressed more directly, e.g., "set environment variable FOO to value WHATEV in all existing screen sessions".
Other useful variations might be:
- allow for updating the values in only a subset of the existing sessions
- allow the new value for the given variable to be obtained from the invoking environment
Of course, if we're going to provide a setenv wrapper, then we'll also want a tool that provides a sort of getenv behavior, as well. That is, something to automate this type of thing:
$ for sess in $(screen-ls); do printf '%s: %s\n' "${sess}" $(screen -S "${sess}" -Q echo '${SSH_AGENT_ID}') || break; done