tmux 未重新连接

发布于 2024-12-29 09:56:31 字数 512 浏览 4 评论 0原文

我最近从使用 screen 切换到 tmux(通过 macports 获得),因为我更喜欢这个功能集。但是,我似乎无法让 tmux 从备用位置重新连接,就像我可以屏幕一样。

在家里的 Mac 上,我将打开 iTerm2,我的默认 shell 是 zsh,然后我将使用 tmux 开始 tmux 会话。我把所有的口水都设置好了,通过 ssh 连接到正确的服务器等,然后工作了一段时间。是时候去上班了。 ; d - tmux 分离。

我开始工作,我使用的是 Windows XP 机器。我启动 putty,通过 ssh 连接到家里的 mac,尝试 tmux Attach,并收到一条错误消息:

没有会话

我似乎看不到以确定为什么会发生这种情况。我并不害怕深入研究这个问题,但我什至不知道从哪里开始。想法?

PS 我已经删除了 .tmux.conf 文件,因此它使用默认配置。

I recently switched from using screen to tmux (obtained through macports), as I like the feature set more. However, I can't seem to get tmux to reattach from an alternate location, like I can screen.

At home on my mac, I will open up iTerm2, my default shell is zsh, and I will begin a tmux session with tmux. I get all my spits set up, ssh'd into the proper servers, etc., and work for a while. Time to go to work. <C-a> d - tmux detaches.

I get to work, where I use a windows xp machine. I fire up putty, ssh into my mac back at home, attempt a tmux attach, and get an error message:

no sessions

I cannot seem to determine why this would happen. I am not afraid to dig into this, but don't even know where to start. Thoughts?

P.S. I have already removed my .tmux.conf file, so it's using the default config.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

与君绝 2025-01-05 09:56:31

就我而言,显然临时文件夹已被清理。
这篇博文帮助我恢复了“丢失”的会话:

我终于找到了解决方案:发送信号 10 强制 tmux 重新创建套接字。之后我可以再次运行 tmux 而不会丢失会话:

$ Killall -10 tmux

In my case, apparently temp folder was cleaned.
This blog post helped me recover my “lost” session:

I finally got the solution: sending the signal 10 forced tmux to recreate sockets. After that I could run tmux again without losing my session:

$ killall -10 tmux
十六岁半 2025-01-05 09:56:31

tmux 将其服务器套接字存储在 TMPDIR 环境变量指定的目录下的目录中。

在 GUI 会话中,您最终可能会得到一个指向 /var 下某处的 TMPDIR(例如 /var/folders/mV/mVip4IQ4EXOriTiLJmeSuk+++Tc/-Tmp-/)。

当您通过 SSH 登录时,您可能最终没有设置 TMPDIR,因此 tmux 在 /tmp/ 下查找其套接字。

在 10.6 系统上,这是我的 TMPDIR,带有 zsh/Terminalzsh/SSH:

% echo local: ${TMPDIR-unset}; ssh localhost 'echo remote: ${TMPDIR-unset}'
local: /var/folders/mV/mVip4IQ4EXOriTiLJmeSuk+++Tc/-Tmp-/
remote: unset

如果您知道需要的值用于 TMPDIR,您可以在附加时指定它(或在会话本身之外运行其他tmux命令):

TMPDIR=/var/folders/mV/mVip4IQ4EXOriTiLJmeSuk+++Tc/-Tmp-/ tmux attach

如果您不知道 GUI 会话使用的目录,您也许能够找到它像这样的东西(语法特定于zsh;它在/var/folders/下搜索名为-Tmp-的目录,该目录由当前用户):

echo /var/folders/**/*/-Tmp-(U/)

为了避免将来出现问题,您可能需要在启动服务器之前取消设置 TMPDIR(或将其设置为您可以更轻松预测的值)。

tmux stores its server socket in a directory under the directory specified by the TMPDIR environment variable.

In your GUI session you probably end up with a TMPDIR that points to somewhere under /var (e.g. /var/folders/mV/mVip4IQ4EXOriTiLJmeSuk+++Tc/-Tmp-/).

When you are logged in through SSH, you probably end up without a TMPDIR set, so tmux looks under /tmp/ for its socket.

On a 10.6 system, here is my TMPDIR with zsh/Terminal, and with zsh/SSH:

% echo local: ${TMPDIR-unset}; ssh localhost 'echo remote: ${TMPDIR-unset}'
local: /var/folders/mV/mVip4IQ4EXOriTiLJmeSuk+++Tc/-Tmp-/
remote: unset

If you know the value you need to use for TMPDIR, you can specify it when attaching (or running some other tmux command outside of the session itself):

TMPDIR=/var/folders/mV/mVip4IQ4EXOriTiLJmeSuk+++Tc/-Tmp-/ tmux attach

If you do not know the directory your GUI session was using you might be able to find it with something like this (the syntax is specific to zsh; it searches under /var/folders/ for a directory named -Tmp- that is owned by the current user):

echo /var/folders/**/*/-Tmp-(U/)

To avoid problems in the future, you might want to unset TMPDIR before starting your server (or set it to something that you can more easily predict).

如此安好 2025-01-05 09:56:31

lsof 的 -U 选项列出了打开的套接字文件,因此 lsof -U | grep '^tmux' 将列出 tmux 使用的所有套接字。如果您没有以启动 tmux 的同一用户身份登录,则需要使用 sudo

每行的最后一列是文件的名称。您关心的文件以 / 开头。

您要查找的行将如下所示:

tmux 1234  username 6u unix 0xffffffabcd123456 0t0 /private/var/folders/M8/M8tFwolmH08fOvJ+-35VI++++TM/-Tmp-/tmux-502/default
tmux 56789 username 6u unix 0xffffff123456789a 0t0 /private/tmp/tmux-502/default

The -U option of lsof lists open socket files, so lsof -U | grep '^tmux' will list all of the sockets in use by tmux. If you're not logged in as the same user that started tmux, you will need to use sudo.

The last column of each row is the name of the file. The files you care about start with a /.

The rows you're looking for will look something like this:

tmux 1234  username 6u unix 0xffffffabcd123456 0t0 /private/var/folders/M8/M8tFwolmH08fOvJ+-35VI++++TM/-Tmp-/tmux-502/default
tmux 56789 username 6u unix 0xffffff123456789a 0t0 /private/tmp/tmux-502/default
近箐 2025-01-05 09:56:31

我对 lsof 建议有一个变体,我一直在使用它来“恢复”TMPDIR 变量,并取得了一些成功,这可以帮助解决许多烦恼。我认为这样做的好处是,人们可以对 lsof 返回的内容更加精确,并且更容易解析出正确的值(偶尔会出现一些非典型字符,但仍然有效) ,曾经输出)。

快速的一句话是:

$ lsof -Fn -d6 -aUc tmux | grep ^n | cut -c2-
/private/var/folders/_l/f_n8blps05xfnkw6fs3dcn_80000gp/T/tmux-502/default

我使用以下脚本(也可能是 ~/.bash_profile 或我认为的其他适当位置中的函数):

#!/bin/bash

if [[ -z "${TMPDIR}" ]]; then
  while read line; do
      case $line in
      n*) line="${line#n}"
          export TMPDIR="${line%%/tmux-$(id -u)/*}"
          ;;
      esac;
  done < <(lsof -Fn -d6 -aUc tmux)
else
    echo ">> \$TMPDIR already defined: $TMPDIR" 1>&2
fi

I have a variation on the lsof suggestion that I have been using with some success to “recover” the TMPDIR variable which can help working around a bunch of annoyances. The advantage, I suppose, is that one can be a little more exacting about what lsof returns and easier to parse out the correct value (on the off-chance at some point some atypical chars, but still valid, ever output).

A quick, one-liner is:

$ lsof -Fn -d6 -aUc tmux | grep ^n | cut -c2-
/private/var/folders/_l/f_n8blps05xfnkw6fs3dcn_80000gp/T/tmux-502/default

I use the following script (could also be a function in ~/.bash_profile or other appropriate place I suppose):

#!/bin/bash

if [[ -z "${TMPDIR}" ]]; then
  while read line; do
      case $line in
      n*) line="${line#n}"
          export TMPDIR="${line%%/tmux-$(id -u)/*}"
          ;;
      esac;
  done < <(lsof -Fn -d6 -aUc tmux)
else
    echo ">> \$TMPDIR already defined: $TMPDIR" 1>&2
fi

https://gist.github.com/jps3/769d50a6a7611949473b

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文