bash 当没有正在运行的会话时,Tmux 无法连接到“tmux ls”上的服务器错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29855506/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tmux failed to connect to server error on `tmux ls` when there are no running sessions
提问by economy
Just writing a quick loop to list out existing tmux sessions when I log into a server, depending on whether tmux is installed (via .bashrc on CentOS).
当我登录到服务器时,只需编写一个快速循环来列出现有的 tmux 会话,这取决于是否安装了 tmux(通过 CentOS 上的 .bashrc)。
if rpm -q tmux; then
echo -e "TMUX sessions running:\n"
echo `tmux ls`
fi
This works great when tmux has a session or two, but if there are no running tmux sessions, I'm getting failed to connect to server: No such file or directory
.
当 tmux 有一两个会话时,这很有效,但如果没有正在运行的 tmux 会话,我会得到failed to connect to server: No such file or directory
.
Is there a way to suppress this?
有没有办法抑制这种情况?
Thanks!
谢谢!
采纳答案by economy
Using a combination of @Barmar and @Etan Reisner 's advice:
结合使用@Barmar 和@Etan Reisner 的建议:
tmux ls 2> /dev/null
Nothing is echoed in when there are no sessions, otherwise the list is reported.
没有会话时不回显任何内容,否则报告列表。
回答by dland
Note that you may have a tmux server running, but you cannot connect to it because someone cleaned out the /tmp
directory and took the server's socket with it.
请注意,您可能有一个 tmux 服务器正在运行,但您无法连接到它,因为有人清除了/tmp
目录并带走了服务器的套接字。
In that case, you can tell the server to recreate the socket by sending it a SIGUSR1 signal.
在这种情况下,您可以通过向服务器发送 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>