Is it possible to start a tmux session on login?

I often SSH into my FreeBSD box as it's running headless. I log in using a normal user and then switch user to root.

I want to automatically create a new tmux session (with the name "my-session") once I su to root. I tried creating a new session by running it from /root/.cshrc but nothing happened (i.e. no sesssion was created). If the session is already created (i.e. I'm already connected to my box on another terminal tab), nothing happens.

Can someone suggest on how to go about it?

Thanks :)
 
Set something like
Code:
/usr/local/bin/tmux attach || /usr/local/bin/tmux new
in your root shell's .rc file (.shrc, .profile, or similar).
 
Strictly speaking, you should use
Code:
[ -x /usr/local/bin/tmux ] && ( /usr/local/bin/tmux attach || /usr/local/bin/tmux new )
 
Back
Top