当没有正在运行的会话时,Tmux无法连接到`tmux ls`上的服务器错误

时间:2015-04-24 19:04:00

标签: bash tmux

当我登录服务器时,只需编写一个快速循环来列出现有的tmux会话,具体取决于是否安装了tmux(通过CentOS上的.bashrc)。

if rpm -q tmux; then
    echo -e "TMUX sessions running:\n"
    echo `tmux ls`
fi

当tmux有一两个会话时,这很有用,但如果没有正在运行的tmux会话,我就会得到failed to connect to server: No such file or directory

有没有办法压制这个?

谢谢!

2 个答案:

答案 0 :(得分:20)

请注意,您可能正在运行tmux服务器,但由于有人清理了/tmp目录并使用了服务器的套接字,因此无法连接到该服务器。

在这种情况下,您可以通过向服务器发送SIGUSR1信号来告诉服务器重新创建套接字。

% ps aux | grep -w [t]mux
root     14799  0.2  0.0  36020   488 ?        Ss   May08  51:30 tmux
% kill -USR1 14799
% tmux ls
<list of tmux sessions>

答案 1 :(得分:2)

Using a combination of @Barmar and @Etan Reisner 's advice:

tmux ls 2> /dev/null

Nothing is echoed in when there are no sessions, otherwise the list is reported.

相关问题