问题
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