2

I have used screen to start a server process, to witch I can later attach if needed and deatach again to carry on with other things. It worked fine but I have found byobu recently and I really love it.

I want to use the same kind of scripts to run the server but instead of a screen sesson I would like to attach it to a byobu tab.

I'm using byobu-tmux (because it looks better). How could I do it?

My original scripts (they both do more, but these are the relevant parts):

# Startup  
screen -a -dmS <name> <command>

# Attach
screen -x <name>

I'm using Ubuntu server 16.04

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
P. Károlyi
  • 21
  • 1
  • 4

1 Answers1

10

I don't know screen commands, so here is a quick sample commands for byobu:

To create new tabs (called screens) inside the current session you can:

byobu new-window "ls -la && sleep 5"

To start a new session (new byobu instance you can attach to) with a command you can:

byobu new-session -s "session name" "ls -la && sleep 5"

To create it already detached:

byobu new-session -d -s "session name" "ls -la && sleep 5"

To attach to a session by name:

byobu attach -t "session name"
bogdan.mustiata
  • 1,725
  • 17
  • 26
  • When I use the first command, the screen/tab closes after the `sleep` command runs out. Is there a way to keep the window open? – sup Nov 16 '16 at 22:35
  • 2
    You can wait for a character after your commands are done: `byobu new-session -s "session name" "ls -la && sleep 5; read -n1"` You press any key and it closes. – bogdan.mustiata Nov 18 '16 at 13:19
  • That is indeed better, thanks. Is there a way to keep it open indefinitely untill I manually close it? – sup Nov 18 '16 at 21:57
  • 1
    I think this is what `read -n1` is going to do anyway, it will keep it open indefinitely until you press a key. I'm not sure what else do you mean. – bogdan.mustiata Nov 22 '16 at 13:46
  • Well, I would prefer if the window did not close after I press a command, so I could use it further. – sup Nov 23 '16 at 15:57
  • 4
    Then add a `&& bash -l` or whatever shell you want to use to the command. – bogdan.mustiata Nov 24 '16 at 08:12