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.

This a deeper explanation for the question.

My goal is:

  1. Start a bash shell configured with a set of environment variables, but running in the background.

  2. Launch about five screen commands in the bash shell, each executing its own commands, but using the environment variables set in the bash shell. The screen commands should all be arranged in the bash window, preferably tiled.

  3. Call up the bash shell later, with the all the screen commands showing.

  4. Close the bash shell and the associated screen when done.

share|improve this question

migrated from stackoverflow.com Dec 29 '12 at 9:32

This question came from our site for professional and enthusiast programmers.

    
@KingSkippus There are quite a few good bash and screen related answers here, so I will give it sometime. –  vfclists Dec 29 '12 at 4:16
add comment

2 Answers

up vote 3 down vote accepted

Well, after some time on your question there is some observations:

line 2: commands should all be arranged in the bash window, preferably tiled is not possible, as when detached, there is no windows.

So when you re-attach, you will always see only one pseudo-tty.

But to do approximatively what asked for, try the following:

First create a RCfile as typing: cat >screenRcTest whith the following:

setenv MyVariable Test
screen -t Top top
screen -t VMStat vmstat -n 1
screen -t OpenPorts watch -n 2 'netstat -tan | grep LISTEN'
screen -t IF-Configs watch -n2 'ip -s link show | grep -v "^ *[RT]X: bytes"'
screen -t "Bourne Again Shell" /bin/bash -i

Than prepare a run wrapper as:

screen -ls | grep -q screenTest || screen -dmS screenTest -c ./screenRcTest

this will run a new screen session in background if not already exist.

For building tiled presentation, prepare another shell script as cat >screenSplitTest

#!/bin/bash

while read line ;do
    screen -X $line
done <<eof
split
split
resize 20
split -v
resize 82
select 0
focus
select 1
focus
split -v
select 2
focus
select 3
focus
select 4
eof

and don't forget chmod +x screenSplitTest.

Finally run the display command as:

xterm -fn 9x15 -geom 160x60 -exec screen -DrS screenTest 

This will open a new window with only a bash ready.

In this inner bash, hit simply:

./screenSplitTest

This will split your window and let you ready again, in your bash session.

result screenshoot

Type now:

echo $MyVariable
Test

So you will see how Environment variable as passed to child bash.

Edit addition:

After doing all, you could hit the following in your inner bash:

trap '[ $(tput lines) == 60 ] && [ $(tput cols) == 160 ] && ./screenSplitTest' WINCH

So you could disconnect by typing: Ctrl-A d than next time you run xterm whith same arguments and geometry, the script screenSplitTest will be initiated automatically.

Edit 2

And now, you could even install this trap in your .bashrc, using MyVariable for ensuring that bash is a child of screenRcTest screen (after moving screenSplitTest to a hidden file in $HOME/.screenSplitTest for constance):

[ "$TERM.$MyVariable" == "screen.Test" ] && \
    trap '[ $(tput lines) == 60 ] && [ $(tput cols) == 160 ] && $HOME/.screenSplitTest' WINCH
share|improve this answer
    
@FHauri All I can say is is Wow! I see you just joined superuser. Where were you in the past when we needed you? :) –  vfclists Dec 30 '12 at 15:59
1  
Thank! I've added a little .bashrc line to make them more automatic. –  F. Hauri Dec 30 '12 at 16:31
add comment

To my knowledge you cannot tile screen instances, but you can tile tmux instances. What you could do is to create an rc-file for the shared environment settings, and then load this to each of your 5 bash shells using bash --rcfile <your file here>.

The bash shells would be started by launching tmux, and when inside, execute some command to create a new split (for instance Ctrl+b % for a vertical split, using standard settings) for each bash instance.

share|improve this answer
    
tmux was another utility I had in mind but I have no experience with it but I know it will be useful one day. –  vfclists Dec 30 '12 at 16:10
add comment

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.