Home > hacking, howto > GNU screen: start with multiple windows and commands

GNU screen: start with multiple windows and commands

July 30, 2010

I wanted to restart my IRC bot on reboot, but I also wanted to have control over it and see its log output, so I wanted to start it inside a screen session. This is nearly trivial, screen -dmS yoursessionname yourcommand is your friend, and you can later on reattach using screen -r yoursessionname.

But what if I want to start multiple commands, each in its own screen window? My first solution used screen -dmS followed by something like screen -r sessionname -X screen; screen -r sessionname -X next; screen -r sessionname -X title "my window title"; screen -r sessionname -X exec "my command line", but it seems that the next command fails in this context, and I ended up with all the mess in one single window.

My next approach (okay, it took me half an hour of reading the manual until here ;-)) was more succesful: I created a session command file which contained screen commands like this:

select 1
title "my window title"
exec mycommand arguments ...

And, voilĂ , I could paste the single command line into my crontab: screen -dmS sessionname && screen -r sessionname -X source sessioncommandfile

Flattr this

Categories: hacking, howto Tags: , ,
  1. Jeremy
    July 22, 2013 at 02:08

    I think `screen -dmS sessionname -c sessioncommandfile` also works.

  1. No trackbacks yet.
Comments are closed.
%d bloggers like this: