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

GNU screen: start with multiple windows and commands

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:

screen
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

Advertisements
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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: