- Published on
Quick and Dirty Service with Screen
- Authors
- Name
- Yair Mark
- @yairmark
Sometimes you have code or one/more scripts that you want to run on a remote server as a service but you do not have the time to set it up as a service.
One quick trick that I use for something I want to run quickly is using GNU Screen.
The steps are quite simple:
- Login to the target server
- Clone / copy the code there
- Start a screen session by running:
screen
- Create the tabs you want:
ctrl-a c
: to create a tabctrl-a shift-a
: to rename a tab
- Then start the script/code you want
- Finally detach from the session:
ctrl-a d
You can safely log out of the server now.
To reattach to the screen session:
- Get the session name:
screen -list
. - Then
screen -r session-name
where you need to replacesession-name
with your screen's session name. You can in fact only use the first few numbers.
The .screenrc
file (which goes in your home ~
directory) I generally use to make screen more user friendly is the one below:
startup_message off
vbell off
hardstatus alwayslastline "%{=b}%{G} %{b}%w %=%{kG}%C%A %D,%d/%m/%y"
shelltitle "Shell"
# Window numbering starts at 1, not 0.
bind c screen 1
bind 0 select 10
# Look and feel
caption always "%{= 2m}%{+b w}Screen: %n | %h %=%t %D %d/%m/%y %c:%s"
hardstatus alwayslastline "%-Lw%{= BW}%50>%n%f* %t%{-}%+Lw%< %=% [%{=b)%{Y}%l%{g}]"
# Left Right meta key mods
# ALT-,. and ALT-<>
bindkey "^[<" eval number !echo $WINDOW-1|bc
bindkey "^[>" eval number !echo $WINDOW+1|bc
bindkey "^[," prev
bindkey "^[." next
select 1