Tmux failed to connect to server error on `tmux ls` when there are no running sessions

百般思念 提交于 2020-02-02 04:34:52

问题


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).

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.

Is there a way to suppress this?

Thanks!


回答1:


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.

In that case, you can tell the server to recreate the socket by sending it a SIGUSR1 signal.

% 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>



回答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.



来源:https://stackoverflow.com/questions/29855506/tmux-failed-to-connect-to-server-error-on-tmux-ls-when-there-are-no-running-se

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!