Skip to content

Instantly share code, notes, and snippets.

@eresonance
Created November 5, 2014 20:55
Show Gist options
  • Save eresonance/9184fc348af21081a66f to your computer and use it in GitHub Desktop.
Save eresonance/9184fc348af21081a66f to your computer and use it in GitHub Desktop.
Changing an environment variable on every open shell on a remote machine
#this only works if your home dir is shared/mounted on every machine
remote="remote.machine.name"
user=$USER
shell=bash
#on login, see if this is an exceed session or not
if [ -n "$XCONFIG_NAME" -a -n "$XSTART_NAME" ]; then
#following is not totally necessary
echo $DISPLAY > ~/.display
#do something crazy, change the DISPLAY variable in every bash terminal
# to the newly created exceed client, but do that on las-sw-01, not the
# current box :P
for pid in $(ssh $remote ps -u $user -U $user | awk "/$shell/"' { print $1 }'); do
echo "pid: $pid"
cat > ~/tmp/gdb_bash <<EOF
attach $pid
call putenv ("DISPLAY=$DISPLAY")
detach
quit
EOF
ssh $remote gdb -quiet -x ~/tmp/gdb_bash 2> /dev/null
done
rm -f ~/tmp/gdb_bash
fi
@eresonance
Copy link
Author

Work is using exceed on demand for X11 forwarding (it's actually fairly nice for GUI stuff) but I like using mosh for shell stuff since it's lighter-weight. What this does is sets the DISPLAY variable in every bash shell open on a specific box (the one I'm using mosh+tmux to connect to) every time a new exceed session is started. This allows me to use mosh for shell stuff onto a box, and then when I run diffuse or gvim or whatever on that shell it will X11 forward using exceed, which renders everything a lot faster than normal ssh X11 forwarding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment