Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

i'd like to launch GNU screen, some shell command in it, then open new screen window(s) with different command(s) - all that automatically, from a script. is it possible?

UPDATE

the screen windows should not be closed after executing the commands, i just want to have the screen session preserved (and detached)

share|improve this question

1 Answer 1

You can put your commands in a file, e.g., myscreenrc, like this:

screen command1
screen command2
screen command3

and then execute screen with the -c option followed by the name of that file, e.g.,

screen -c myscreenrc

UPDATE

in reponse to the updated question. The commands I used for testing were screen vim foo and screen vim bar, so I didn't see the screen-closing problem. The following solves the screen-closing problem, but it seems a bit of a kludge.

screen bash -c 'ls foo; exec bash -i'
screen bash -c 'ls bar; exec bash -i'

ls was just a convenient command for testing this problem.

UPDATE #2

Another approach would be to start the command from the shell's rc file rather than from screen's rc file. It requires another file for each command, though. For example, to run top in a screen window such that quitting top will return you to a bash prompt in that same window, create a file, call it runtop, that contains the following:

. ~/.bashrc
top

Then put this line in the file we're calling screenrc:

screen bash --rcfile ~/runtop -i

and start screen as

screen -c screenrc
share|improve this answer
    
interesting, it does the job and quits, but i need the screen windows to stay.. maybe i should make my question more clear –  mykhal Oct 12 '10 at 7:02
    
good work, but it's not ideal, if i launch bash with some command, i'd like the shell to not quit, not run the new shell. for interactive tasks, e.g. bash -i -c top it's usable, unfortunately, shell quits immediately after quitting the top. –  mykhal Oct 13 '10 at 11:27
    
@mykhal: See if UPDATE #2 to my answer helps. –  garyjohn Oct 13 '10 at 15:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.