Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

bash

tmux

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!

like image 632
economy Avatar asked Apr 24 '15 19:04

economy


2 Answers

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>
like image 100
dland Avatar answered Oct 01 '22 12:10

dland


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.

like image 29
economy Avatar answered Oct 01 '22 12:10

economy