Last active
January 26, 2017 18:55
-
-
Save jrbenito/259e4030dce480e8a3e7d24e219175aa to your computer and use it in GitHub Desktop.
Set display variable when reconnect to a tmux terminal on a server with many users (display can change on each ssh section)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setdisplay () | |
{ | |
USERID=$(id -u); | |
# list all connections by numeric (don´t wait slow DNS) | |
# and filter by current user´s listening ports on localhost | |
# that that is in the range of 6000 ~ 6999 (generally X ports) | |
PORTA=$(netstat -ane|grep "LISTEN "|grep "$USERID"|sort -k8n|sed -n -e "s/.*127\.0\.0\.1:6.\(..\) .*/\1/p"|tail -n 1); | |
export DISPLAY="localhost:$PORTA.0" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment