I have a system on a remote server that maintains context and tmux sessions since I frequently lose connection on my laptop due to workflow.

The current script restores a tmux session on connection, or creates a new one if there are no currently detached sessions. This works great, however the downfall is if I need to quickly bring up a new session on the server, I first have to connect n times to attach all of the recently detached sessions.

I'd like to somehow send information to the server when connecting that says "open this one in a new session, regardless of existing sessions".

Is it possible to send data to a remote host, such that the bashrc file can interpret it?

  • I'm not sure I get it right. Some code to reproduce the problem may be useful. I use Bash on my (remote) Debian; .bashrc checks if it's inside tmux; if not, it runs tmux a || tmux. This way I always jump into tmux, I guess your system is somewhat similar. If I want a new session after this automatic tmux a, I manually detach and just invoke tmux. This requires the original shell to be still there, so commands in .bashrc cannot be like exec tmux a. Detaching and typing tmux is easy, I have never sought alternatives. One is ssh -t a@b exec tmux, at least in my case. – Kamil Maciorowski Sep 26 at 11:00
  • I could just detach, however my script looks for existing connections based on a naming scheme, so that they reconnect in order. If I was launching, I would have to look up and follow this naming scheme. I guess basically what I'm asking is how do I send data to the remote bashrc? From there I can write the data handling no problem – Brydon Gibson Sep 26 at 13:29
  • Still I don't know your exact system, I can only shoot in the dark. How about ssh -t a@b 'exec bash --rcfile /some/custom/bashrc'? With prior scp /onthefly/temporary/bashrc a@b:/some/custom/bashrc if needed. Or ssh -t a@b "var1='$localvar1' var2='$localvar2' exec bash -i" and let your common remote bashrc act according to var1, var2 etc. – Kamil Maciorowski Sep 26 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.