HOME ESR EXPERIMENTS LABS etc
NucAR lab laser_lab Fritz-Bosch-Lab X-Ray Lab target Beavertail
  NucAR lab  Not logged in ELOG logo
Message ID: 10     Entry time: Fri Dec 11 10:44:45 2020
Author: Jan 
Category: misc 
Subject: screen config and specialties 
A brief summary of handy features of screen useful, e.g., for daq operation.

1. invoke screen with a prepared config file
This will automatically set up a prepared environment
screen -S session-name -c config_file
an example config_file is attached: ".screen_e127"
it includes key-bindings, several prepared tabs and a bunch of commands for each tab and was used in 2020 for e127 experiment.

2. send external commands into a specific tab of a specific screen session
screen -S e127 -p 0 -X stuff "^C"
screen -S e127 -p 0 -X stuff "sleep 2;./start.sh^M"
screen -S e127 -p 4 -X stuff "sleep 10; empty stream://r4l-58 --server=stream:6002^M"
With this the remote control of screen by a GUI or so is possible.
This injects ctrl-c:
stuff "^C"

And each command has to submitted with the concluding <RETURN>:
stuff "top^M"

3. enable passwordless ssh inside a screen
When you invoke screen as a child of ssh-agent and you have encrypted ssh-keys set, you need to type the passphrase only once before opening the screen. Any internal ssh then won't need password.
exec /usr/bin/ssh-agent xterm -g 100x20 -e "ssh-add; screen -S session-name -c config_file" &
Here you start an xterm that will be killed as soon as the screen terminates. Only inside this xterm your ssh-agent has the keys. ssh-add will only find keys in default location ~/.ssh/ but you could also specify a certain key.
Attachment 1: .screen_e127  1 kB  | Hide | Hide all
# this is a nice caption including tab names
caption always "%{= kw}%-w%{= gW}%n %t%{-}%+w %-= storage rings rule! - %Y-%m-%d %C:%s"

# don't display the copyright page
startup_message off

# autodetach session on hangup instead of terminating screen
autodetach on

# increase scrollback buffer size
defscrollback 10000

# navigating regions with Ctrl-arrows
bindkey "^[[1;5D" focus left
bindkey "^[[1;5C" focus right
bindkey "^[[1;5A" focus up
bindkey "^[[1;5B" focus down

# switch windows with F3 (prev) and F4 (next)
bindkey "^[OR" prev
bindkey "^[OS" next


# create windows
chdir /lynx/Lynx/esr/usr/litv-exp
screen -t DRASI     #0
screen -t LOG       #1
screen -t RATE      #2
screen -t TRLO      #3
chdir $E127_DATADIR
screen -t STREAM    #4
screen -t FILE      #5
chdir /u/litv-exp/e127/UDP/build_cc_x86_64-linux-gnu_4.9.2_debug
screen -t UDP       #6
screen -t udp       #7
screen -t sync	    #8

# start logger
select 1
stuff "ssh r4l-58^M"
stuff "cd 2020_e127/r4l-58/^M"
stuff "./logger.sh^M"
# start daq rate monitor
select 2
stuff "ssh r4l-58^M"
stuff "cd 2020_e127/r4l-58/^M"
stuff "./rate.sh^M"
stuff "^M"
# start drasi
select 0
stuff "ssh r4l-58^M"
stuff "cd 2020_e127/r4l-58/^M"
stuff "sleep 1; ./start.sh^M"
# start trlo edit
select 3
stuff "ssh r4l-58^M"
stuff "cd 2020_e127/r4l-58/^M"
# start stream server
select 4
stuff "sleep 10; empty stream://r4l-58:6002 --server=stream:6002^M"
select 5
#stuff "sleep 5; empty trans://r4l-58:6000 --server=trans:6000^M"
# start UDP repeater
select 6
stuff "./udp_repeater^M"
# start UDP reader
select 7
stuff "E127_rates^M"
select 8
stuff "ssh lxg0188^M"
stuff "cd /data.local2/E127_lmd^M"
select 2
#detach
ELOG V3.1.5-fc6679b