date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,404,212,370,000
Is there a way to detach all terminals from a running tmux session, except the one i'm actually using? It seems a little weird, but the meaning of doing this is to keep some "persistency" layer to end user remote session, while ensuring that the user is using the system on only "one shell". As explained here, it's easy to create sessions based on user names: if [[ "$TMUX" == "" ]] && [[ "$SSH_CONNECTION" != "" ]]; then # Attempt to discover a detached session and attach # it, else create a new session WHOAMI=$(whoami) if tmux has-session -t $WHOAMI 2>/dev/null; then tmux -2 attach-session -t $WHOAMI else tmux -2 new-session -s $WHOAMI fi fi But i want also, to make sure that the last attached terminal is the only one that remains attached to the user's tmux session. Does it have a way to accomplished that? I also accept solutions based on screen (or other multiplexers) ;)
If I've understood your question correctly, the -d option to attach-session does what you want: tmux -2 attach-session -d -t $WHOAMI This attaches to the named target session and detaches all other clients. You can do something similar after the session is attached, with detach-client's -a and -t options: name the client with -t, and add -a to detach all clients apart from the named client. screen also has a -d option which does the same thing.
Detach all other terminals except current one from a tmux session
1,404,212,370,000
I want to create a screen shortcut ^q to detach from the current session. In Tmux I would use bind -n command. In screen I'v tried: bind q detach works with prefix as C-a q bind ^q detach doesn't work at all Is that even possible to bypass prefix in the screen so simple C-q could work?
You chose a difficult character. For example, if you had tried Control-P it would have been a bit easier, ie (using bindkey not bind): bindkey ^p detach and it would have worked. You can try the same with ^q and it probably won't seem work. The problem is that Control-Q is also used by your tty to do flow-control (xon/xoff). As you probably are not interested in flow-control, you could disable it in your tty with the shell command stty -ixon and then Control-Q should work.
Bind Screen shortcut to Ctrl+Q without prefix
1,404,212,370,000
I am facing problems with my configuring screen. My screen.rc is very simple and looks like this: altscreen on termcapinfo xterm ti@:te@ I wanted to configure screen to have the same behavior as if I connected directly using SSH client like MobaXterm. So what I wanted to achieve was: A possibility to scroll in vim (without using set mouse a) with mouse Scrolling terminal output with mouse (without Ctrl + A Esc) After exiting vim and other editors etc. I want to see my previous commands, not the vim output nor have my screen cleared. Also configuring .vimrc (and similar local config files) is impossible because I'm using screen to connect to many many machines and I am not able to modify .vimrc on all of them. I found out that achieving all of this is impossible. So with those two lines in my .screenrc I am able to scroll the terminal output but in vim I have to use the keyboard - ok. So, going straight to the problem. When I close vim I get a very strange behavior. The output of the console is like it was before opening vim so it's what I want. But the prompt is at the top of the window instead of being after my last command (running vim). So I'm writing on top of some previous output. I hope you understand. Do you know how to fix it? Any help would be appreciated. I don't know if it is meaningful but I am connecting using MobaXterm to a virtual machine when I have my screen configured. Maybe it's also related to SSH, who knows. Edit: I tried also another ssh clients like Putty and it's the same
It turned out the problem was caused by a stupid line in .bashrc TERM=xterm; export $TERM so after running screen it had TERM=xterm instead of TERM=screen. After removing this line the problem disappeared.
Screen - weird behavior after exiting Vim
1,404,212,370,000
The program I want use can be started via ./myprogram < input_part1.txt > output_part1.txt How can I start four jobs of myprogram in a BASH-script where each job runs in a separate SCREEN-session? The sessions do not exist before I start the script. I tried: #!/bin/bash screen -mdS test1 ./myprogram < input_part1.txt > output_part1.txt screen -mdS test2 ./myprogram < input_part2.txt > output_part2.txt screen -mdS test3 ./myprogram < input_part3.txt > output_part3.txt screen -mdS test4 ./myprogram < input_part4.txt > output_part4.txt but this does not work. Why not?
For a single session, I use something like that: cat > screenrc-test <<EOF screen -t test1 sh -c "./myprogram < input_part1.txt > output_part1.txt" screen -t test2 sh -c "./myprogram < input_part2.txt > output_part2.txt" screen -t test3 sh -c "./myprogram < input_part3.txt > output_part3.txt" screen -t test4 sh -c "./myprogram < input_part4.txt > output_part4.txt" EOF screen -S test-all -c screenrc-test I don't know why you want several sessions, but the syntax is, in a similar way: screen -mdS test1 sh -c "./myprogram < input_part1.txt > output_part1.txt" for each session. Using a shell is necessary for the redirections, otherwise the redirections would be applied to the screen command instead of myprogram. An example: #!/bin/sh screen -mdS test1 zsh -c "repeat 4 { date; sleep 1; } > out1" screen -mdS test2 zsh -c "repeat 4 { date; sleep 1; } > out2" screen -mdS test3 zsh -c "repeat 4 { date; sleep 1; } > out3" After running it (and waiting for 4 seconds), I get: ==> out1 <== Tue Sep 2 09:23:07 CEST 2014 Tue Sep 2 09:23:08 CEST 2014 Tue Sep 2 09:23:09 CEST 2014 Tue Sep 2 09:23:10 CEST 2014 ==> out2 <== Tue Sep 2 09:23:07 CEST 2014 Tue Sep 2 09:23:08 CEST 2014 Tue Sep 2 09:23:09 CEST 2014 Tue Sep 2 09:23:10 CEST 2014 ==> out3 <== Tue Sep 2 09:23:07 CEST 2014 Tue Sep 2 09:23:08 CEST 2014 Tue Sep 2 09:23:09 CEST 2014 Tue Sep 2 09:23:10 CEST 2014 showing that the commands are run in parallel.
How to start several jobs in different screen sessions in a Bash-script?
1,404,212,370,000
The bindkey keyword in .screenrc is preceded by some cryptic keys that correspond to some keybouard binding. How can I figure out what these are? Google and GNU Screen Documentation did not show the results I was looking for. For example, how would you found the bindings below without someone specifically telling you what the binding is? bindkey "^[[1;5I" next bindkey "^[[1;6I" prev
The keycodes vary somewhat from terminal to terminal, but check out this resource.
screenrc: find out the keys bound by bindkey
1,404,212,370,000
The following command screen -t 'fubar' cmd will create a new screen window with the command cmd running in it and will set the focus to this window. How can I keep the focus in the current screen window, not the new one?
I'm not sure that you can do it in one go, here is a workaround: screen -t 'fubar' cmd & sleep .01; screen -X other
Start a GNU screen window in the background/without focus
1,404,212,370,000
I run a lot of long running processes (simulations) that print progress to STDOUT. I occasionally forget to redirect to STDOUT to a file I can grep, and it's usually too far along to restart. QUESTION: Without stopping the process, is there a way I can hook into another STDOUT? These are always running in GNU screen with ZSH on OS X 10.7.3.
There is a clever hack mentioned here that uses GDB to attach to the process, and a utility named dupx wraps up this functionality. From the dupx manpage: Dupx is a simple utility to remap files of an already running program. Shells like Bash allow easy input/output/error redirection at the time the program is started using >, < - like syntax, e.g.: echo 'redirect this text' > /tmp/stdout will redirect output of echo to /tmp/stdout. Standard shells however do not provide the capability of remapping (redirecting) of output (or input, or error) for an already started process. Dupx tries to address this problem by using dup(2) system call from inside gdb(1). Dupx is currently implemented as a simple shell wrapper around a gdb script.
Redirecting/grep'ing an existing shell's STDOUT
1,404,212,370,000
I have a remote server running CentOS 7 I can only access by SSH. I want two java servers running on them at all times, even after ISP does reboots etc. S So I have tried to make a systemd service that starts the two java servers in a screen. I do not get any error messages when I start the service but it instantly dies: (systemctl status -l blogpatcher.service) * blogpatcher.service - Start blogpatcher servers Loaded: loaded (/etc/systemd/system/blogpatcher.service; enabled; vendor preset: disabled) Active: inactive (dead) since Sat 2020-02-08 04:19:09 EST; 7s ago Process: 22388 ExecStart=/usr/bin/bash /home/blogpatc/script/blogpatcher.sh (code=exited, status=0/SUCCESS) Main PID: 22388 (code=exited, status=0/SUCCESS) Here is blogpatcher.service file: # vi /etc/systemd/system/blogpatcher.service [Unit] Description=Start blogpatcher servers After=network.target [Service] Type=simple ExecStart=/usr/bin/bash /home/blogpatc/script/blogpatcher.sh TimeoutStartSec=90 [Install] WantedBy=default.target Here is the script file that the service run: # vi /var/tmp/test_script.sh #!/bin/bash screen -dmS syn bash -c 'cd /home/blogpatc/server/;java -cp bloghelper_artifact_main.jar com.aperico.bloghelper.server.ThesaurusServer;exec bash' If I just run the script file from SSH console it works as intended and since there is no error message I am a bit stumped and wondering if anyone knows what the problem is?
Adding: "RemainAfterExit=yes" under the [Service] section will let the screen remain open.
Problem setting up systemd service to run screen at reboot
1,404,212,370,000
How can I get a confirmation before I exit screen (when typing exit on the command-line). Is this possible?
I approached this by masking the exit command with a function; the function checks to see if you're within screen, and if you're the only child process left of that screen process. exit() { if [[ "$(ps -o pid= --ppid "$(ps -o ppid= -p "$$")" | wc -l)" -eq 1 ]] then read -p "Warning: you are in the last screen window; do you really want to exit? (y/n) " case $REPLY in (y*) command exit "$@" ;; esac else # not within screen at all, or not within the last screen window command exit "$@" fi } You would have to include that function as part of your (bash) profile, e.g. ~/.bash_profile. When starting screen, it will (unless told otherwise), start an instance of your $SHELL. That shell will be a child of a screen process. When exiting from a child shell, the above code checks to see how many processes are children of the current shell's parent process. From the inside out: $(ps -o ppid= -p "$$") -- asks for the parent PID (adding the = suppresses the header line) of the current process ($$) $(ps -o pid= --ppid ... | wc -l) -- asks for the list of PIDs (again without the header) whose parent PID is our parent, then counts the number of lines of output If it looks like we're the last child process of a screen session, it prompts for confirmation; if the response begins with the letter y, the function calls the "real" exit command to exit the shell; otherwise, the function ends without exiting the shell. If we're not the last child process, the function goes ahead and exits normally. A couple notes as I developed this: I initially had more tests in the if line to see if we are within a screen session, including seeing if STY is populated and for SHLVL being greater than 1. screen sets STY, and bash will increment SHLVL, but neither of those variables are read-only, so the test is not strong enough to be useful. screen also sets a WINDOW variable, but checking it for 0 is not reliable; you could open two windows and then close window 0, leaving window 1 as the last window. Entering EOF (usually Control+D) will, by default, cause the shell to immediately exit, bypassing this wrapper function. The best workaround I know would be to set the variable IGNOREEOF to some non-zero value; that will only delay the shell's inevitable exit, though. Because I used so many bash- (and GNU procutils-) specific features above, I wanted to also provide a POSIX-conformant solution. The ps line changes to a ps ... | grep -c scheme in order to capture the number of processes with a specific parent PID. The other change is to re-work the read -p into a separate prompt and read. exit() { parent="$(ps -o ppid= -p $$)" if [ "$( ps -eo ppid= | grep -c "^ *${parent}\$" )" -eq 1 ] then printf "Warning: you are in the last screen window; do you really want to exit? (y/n) " read REPLY case $REPLY in (y*) command exit "$@" ;; esac else # not within screen at all, or not within the last screen window command exit "$@" fi }
How can I get a confirmation before exiting screen?
1,404,212,370,000
I'm trying to figure out how to create a command called runbg that will accept sub-commands to run in the background and create a split screen for each sub-command. When a sub-command completes successfully, the split screen is closed; if a sub-command fails, then the screen stays open with the error until the user closes the screen with the terminate signal. Once all screens are closed, the command is complete and execution continues. E.g. runbg "ping -t 5 google.com" "ping -t 10 microsoft.com" echo "done" I've discovered I can do: ping -t 5 google.com & ping -t 10 microsoft.com & wait Which accomplishes the parallel side of things, however each command outputs everything to the same terminal, which is very noisy. Hence the desire for a split screen setup. From searching here, I've discovered GNU Screen which seems to handle the screen side of things, but it seems it requires a .screenrc file - which while possible to do programmatically, is a bit annoying, as I'd imagine it would mean I would need to write a random tmp file somewhere. I found this answer which goes into using screen without the .sreenrc however I cannot figure out how to do the split screen stuff in it. So in short: Is there something that already does the functionality that I'm aiming for with runbg? If not, is GNU Screen what I want for this? Do I need to use a .screenrc file, or is there a way to accomplish the split screens without one?
You can do it with tmux by stringing together split-window and send-keys like this: tmux new session \; split-window -v \; send-keys 'ping -t 5 google.com' C-m \; split-window -h \; send-keys 'ping -t 10 microsoft.com' C-m \;
Programmatically run background tasks in a split screen?
1,404,212,370,000
Since I have started using screen to start text-mode (console) email client (namely alpine), I have never lost partially written email due to network disconnect. Very useful. However starting email client is now a bit involved: Check if there is old session with screen -list Depending on the previous step: If there is one, reconnect with screen -U -r <number> If there isn't one, start email client with screen -U alpine How can I simplify these steps so that I can run only simple command (simple script), that is start_or_reconnect alpine? We can assume that if there is more than one session active it is an error, or just use the first one...
Use an explicit session name (-S option), and use -RR to reattach to an existing session or create one if there is none. alias m='screen -S alpine -d -RR alpine'
How to reconnect to 'screen' session or start a new command
1,404,212,370,000
I have a python script that will write some general logging to the console. I've redirected this to a log file using the typical python -u jbot.py | tee -a jbot.log. This works fine, I get console output and logfile input. However, when attempting to run this under screen: screen python -u jbot.py | tee -a jbot.log I don't get any of the logging output to my file. Once I've disconnected from screen, does console output for that session get suppressed entirely, or is there a way I can still have logfile input from the stdout and stderr of my script? I realize using a logging library would probably solve this (since I'm screening anyhow), but for now I want to stick with capturing console output (if possible) until I can properly integrate a logging module into my code.
You need to do something like this: screen sh -c 'python -u jbot.py | tee -a jbot.log' Basically, before you were piping the output of screen (not of your python script directly) to the log. Screen takes a command to execute as its argument, which it does itself not using a shell. So you need to explicitly make it run a shell. Another option is to use screen's built-in output logging; see the -L option (also available inside screen via its UI).
No logfile output when running script under screen, with console redirect (tee)
1,404,212,370,000
Depending on how I run screen, it either does or does not have the right TERMCAP info. The symptom of this is that colors don't always show up in my terminal correctly (eg: ls, vim syntax highlighting, etc). This works fine: $ echo $TERMCAP <empty output> $ screen -S foo $ screen -r foo <now I'm inside a screen session> $ echo $TERMCAP <long output> $ ls <nice pretty colors> This has problems: $ echo $TERMCAP <empty output> $ screen -d -m -S foo $ screen -r foo <now I'm inside a screen session> $ echo $TERMCAP <long output, but different than before> $ ls <no colors ):> Now, I can work around this. I can fiddle with my TERMCAP manually, etc. But I'd really like to understand what's going on. I'd like to find a 'clean' solution, if possible. Does anybody know what's going on here? What difference should it make if I use -d -m when running screen? This is on FreeBSD, if that matters.
When you use the -d -m options, screen starts in detached mode, and in that case does not attempt to improve its terminal description based on your current TERM variable. It only looks for your TERM variable when it is started normally (not detached). When you attach to the session which was started detached, it is too late to do this initialization based on TERM. The section 16.1 Choosing the termcap entry for a window in the manual describes some of the fixes it does. What you saw for the non-working case looks like this: TERMCAP=SC|screen|VT 100/ANSI X3.64 virtual terminal:\ :DO=\E[%dB:LE=\E[%dD:RI=\E[%dC:UP=\E[%dA:bs:bt=\E[Z:\ :cd=\E[J:ce=\E[K:cl=\E[H\E[J:cm=\E[%i%d;%dH:ct=\E[3g:\ :do=^J:nd=\E[C:pt:rc=\E8:rs=\Ec:sc=\E7:st=\EH:up=\EM:\ :le=^H:bl=^G:cr=^M:it#8:ho=\E[H:nw=\EE:ta=^I:is=\E)0:\ :li#24:co#80:am:xn:xv:LP:sr=\EM:al=\E[L:AL=\E[%dL:\ :cs=\E[%i%d;%dr:dl=\E[M:DL=\E[%dM:dc=\E[P:DC=\E[%dP:\ :im=\E[4h:ei=\E[4l:mi:IC=\E[%d@:ks=\E[?1h\E=:\ :ke=\E[?1l\E>:vi=\E[?25l:ve=\E[34h\E[?25h:vs=\E[34l:\ :ti=\E[?1049h:te=\E[?1049l:k0=\E[10~:k1=\EOP:k2=\EOQ:\ :k3=\EOR:k4=\EOS:k5=\E[15~:k6=\E[17~:k7=\E[18~:\ :k8=\E[19~:k9=\E[20~:k;=\E[21~:F1=\E[23~:F2=\E[24~:\ :kh=\E[1~:@1=\E[1~:kH=\E[4~:@7=\E[4~:kN=\E[6~:kP=\E[5~:\ :kI=\E[2~:kD=\E[3~:ku=\EOA:kd=\EOB:kr=\EOC:kl=\EOD: while the good one looks like this: TERMCAP=SC|screen|VT 100/ANSI X3.64 virtual terminal:\ :DO=\E[%dB:LE=\E[%dD:RI=\E[%dC:UP=\E[%dA:bs:bt=\E[Z:\ :cd=\E[J:ce=\E[K:cl=\E[H\E[J:cm=\E[%i%d;%dH:ct=\E[3g:\ :do=^J:nd=\E[C:pt:rc=\E8:rs=\Ec:sc=\E7:st=\EH:up=\EM:\ :le=^H:bl=^G:cr=^M:it#8:ho=\E[H:nw=\EE:ta=^I:is=\E)0:\ :li#25:co#80:am:xn:xv:LP:sr=\EM:al=\E[L:AL=\E[%dL:\ :cs=\E[%i%d;%dr:dl=\E[M:DL=\E[%dM:dc=\E[P:DC=\E[%dP:\ :im=\E[4h:ei=\E[4l:mi:IC=\E[%d@:ks=\E[?1h\E=:\ :ke=\E[?1l\E>:vi=\E[?25l:ve=\E[34h\E[?25h:vs=\E[34l:\ :ti=\E[?1049h:te=\E[?1049l:us=\E[4m:ue=\E[24m:so=\E[3m:\ :se=\E[23m:md=\E[1m:mr=\E[7m:me=\E[m:ms:\ :Co#8:pa#64:AF=\E[3%dm:AB=\E[4%dm:op=\E[39;49m:AX:G0:\ :as=\E(0:ae=\E(B:\ :ac=\140\140aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~..--++,,hhII00:\ :k0=\E[10~:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:k5=\E[15~:\ :k6=\E[17~:k7=\E[18~:k8=\E[19~:k9=\E[20~:k;=\E[21~:\ :F1=\E[23~:F2=\E[24~:kb=^H:K2=\EOE:kB=\E[Z:kh=\E[1~:\ :@1=\E[1~:kH=\E[4~:@7=\E[4~:kN=\E[6~:kP=\E[5~:kI=\E[2~:\ :kD=\E[3~:ku=\EOA:kd=\EOB:kr=\EOC:kl=\EOD:km: In the good case, screen noticed that TERM was set to xterm, and added capabilities from that description. You will notice this problem with FreeBSD because the termcap distributed with screen does not have color, when you limit the description to the 1023-byte limit assumed by termcap applications (the extra settings are discarded). On other platforms, you likely would be using the description provided by ncurses, which does tell how to use color. The difference is not due to the library used; although screen is a termcap application, it uses ncurses on FreeBSD: $ ldd `which screen` /usr/local/bin/screen: libncurses.so.8 => /lib/libncurses.so.8 (0x80086a000) libelf.so.1 => /usr/lib/libelf.so.1 (0x800ab6000) libutil.so.9 => /lib/libutil.so.9 (0x800ccb000) libulog.so.0 => /lib/libulog.so.0 (0x800edd000) libcrypt.so.5 => /lib/libcrypt.so.5 (0x8010df000) libc.so.7 => /lib/libc.so.7 (0x8012ff000) libmd.so.6 => /lib/libmd.so.6 (0x801698000) Instead, the difference is due to FreeBSD builds ncurses using the termcap database in preference to terminfo (you can get the terminfo database using a port), and FreeBSD has a termcap file, which does not match other terminal databases. While some fixes have been made, it still has quirks such as VT100s with color, and modifications to make the differences between its console with TERM=xterm and a real xterm less apparent (except to people using xterm, of course). Somewhat ironically, one may notice that screen sets TERMCAP to a multi-line format. That was used in 4.2BSD and 4.3BSD, but made obsolete in 4.4BSD (around 25 years ago), with the switch to using hashed databases and at the same time discarding the whitespace (which counted against the 1023 byte limit on termcap size). Since FreeBSD switched to using ncurses in the 1990s, that format is more out of date, with few applications relying on the TERMCAP variable. But ls is one of those. screen does have an option -T which should help with this by specifying a particular termcap entry (which has color), but on testing it, appears that cannot solve the problem. Further reading: TERM=xterm lacking smcup and rmcup (alternate screen) Alternate screen on FreeBSD's sc and vt Alternate screen buffer in Xterm/FreeBSD FreeBSD termcap file
GNU Screen: Strange TERMCAP when using -d -m
1,404,212,370,000
I am trying to create a new screen so that the screen is detached at first, and its current folder is cd /home. When I execute screen -dm "cd /home" (the parameter -dm means "Start screen in detached mode. This creates a new session but doesn't attach to it".) I get the error message: Cannot identify account 'cd '.` However, when I execute screen -dm "$(cd /home)", there is no error message, but the current folder in the created screen isn't /home. Why?
The latter screen -dm "$(cd /home)" is substituted by the shell to get the message from CDPATH which shows which directory was reached by the cd command. But the cd command only applies to the subshell, and not the command-line that screen sees. The former is not substituted, and screen does not know what to do with a directory named "cd /home" Perhaps you meant something like this (no quotes): screen -dm cd /home which fits into the pattern listed in the manual page: screen [ -options ] [ cmd [ args ] ]
screen -dm: "Cannot identify account"
1,404,212,370,000
I want to run some long calculation jobs in the background. I choose screen. However I found screen didn't accpet redirection. for example screen -dmS name ls>ls.dat won't generate ls.dat. Fortunately, screen -L will output screen's log to a file. However, what it does is to append to previous log file, even if I pkill screen and start a fresh new screen. Is there a way to force it to overwrite the previous log file when starting a new screen?
I don't believe you can force screen to overwrite the log. It logs to screenlog.%n by default, where %n is the screen window number (so each window has it's own log). If that file exists, it appends to it. However, you can tell screen to use a different filename, including a timestamp, so you'll get a new log file each time, but you'll then need to manage the old logs. In .screenrc you can put the following line, logfile /path/to/log/screenlog-%n-%Y%m%d-%c:%s to create log files that include the window number (%n) and the year, month, date, and time. Alternatively, you could create a bash alias that deletes the log file before running screen, for example, alias screen='rm /path/to/log; screen' If you want to affect screen log files in the current directory, just remove /path/to/log/ from the commands above. Lastly, depending on what you're trying to achieve, the Linux tool script might be more useful than just logging in screen. man script for more information.
how to force `screen -L` to overwrite log?
1,404,212,370,000
I'm having a hard time finding a "command character" for GNU-screen that does not collide with some key combination that I already use. Through Emacs (and org-mode, and my regular shell, etc.), pretty much all the command characters consisting of Ctrl + [A-Z] are off-limits. I figure that, if there were a simple, and consistent, way to type any one of the characters in the ASCII range 27 through 31, that may do the trick. Are there any tools I could use to find a way to type one of these characters that fits the above criteria? (BTW, by "consistent" I mean that it can be typed the same way in "all keyboards", or at least in "all US keyboards".)
You can use any function key that Screen recognizes as the escape character. Set the escape character (more precisely, the escape byte) to one that you never type, for example \377 which is never used by UTF-8. Bind the key you want to use as the escape key to command, for example F12 (which is F2 in termcap speak — see the section “Input translation” in the Screen manual): escape \377\377 bindkey -k F2 command You aren't limited to keys for which Screen knows a symbolic name. To set an arbitrary key or keychord as the command key (the key does need to send an escape sequence in the terminal), find out what escape sequence it sends by pressing Ctrl+V then that key at a shell prompt. This causes the escape sequence to be inserted literally, instead of being recognized by the shell as an escape sequence. For example, if you wanted to use F12, you could press Ctrl+V then F12, which inserts ^[[24~ (the first ^[ represents the escape character) (some terminals may send a different escape sequence); then you would use bindkey ^[[24~ command I use Ctrl+\ as my Screen escape key (escape ^\\\), and let Ctrl+\ \ inject a ^\ character. Few programs use the ^\ control character. In Emacs, it calls toggle-input-method, which I don't use; your mileage may vary. In a cooked terminal, it sends SIGQUIT, which is rarely useful (when it's needed, Ctrl+Z followed by the kill command usually works as well; I default to having core dumps disabled). Ctrl+\ can be difficult to type on some keyboard layouts where \ requires AltGr, but on the US layout it's straightforward. I also configure my terminal emulator to send the ^\ character when I press Ctrl+`, which lets me type it with the left hand as well. Ctrl+] (Emacs: abort-recursive-edit) and Ctrl+^ (Emacs: undefined; but it's awkward to type on a US keyboard as well as on many other layouts) are other likely candidates for an Emacs user. By the way, if you only use Screen to run Emacs and some shells, you don't need Screen. Emacs can play the same role. Keep a single Emacs process running, and use emacsclient to open a window on this Emacs process from any terminal. If the terminal goes away, you can run emacsclient again to connect to the same Emacs instance. You can have as many instances of emacsclient as you like that are connected to the same Emacs instance, possibly displaying through different local and remote connections. To start Emacs with no interface, run emacs --daemon. Then run emacsclient -c to open a window to the existing Emacs instance (or emacsclient -c -nw to force a text mode window). If you want to start Emacs if it wasn't already started but connect to the existing Emacs instance if there is one, run emacsclient -a '' -c. If you want to run shells, you can use M-x shell or M-x term or the like inside Emacs. Emacs can do pretty much everything Screen can do.
How to search for a suitable "command character" for GNU-screen?
1,404,212,370,000
I have zsh shell in a Linux server, and connect to the server from screen sessions in different computers. I'm trying to get control keys, such as home and end, to function correctly. Because zsh doesn't use the GNU Readline library, I need to take care of mapping the terminal sequences to zsh commands. First I use zkbd to find out the sequences sent by each key stroke, and then I map them to the correct commands. This is what I have in .zshrc: autoload zkbd [ ! -f "${ZDOTDIR:-$HOME}/.zkbd/$TERM-${DISPLAY:-$VENDOR-$OSTYPE}" ] && zkbd source "${ZDOTDIR:-$HOME}/.zkbd/$TERM-${DISPLAY:-$VENDOR-$OSTYPE}" [ -n "${key[Backspace]}" ] && bindkey "${key[Backspace]}" backward-delete-char [ -n "${key[Home]}" ] && bindkey "${key[Home]}" beginning-of-line ... Now I have two problems: Usually when I connect to the server, the sequence number in $DISPLAY environment variable gets a new value. Consequently, zkbd gets run, and I have to go through pressing all the control keys. Is it necessary to have the key sequences dependent on $DISPLAY? When I connect to the server from a screen session, $TERM environment variable will be set to screen. Still, depending on which computer I'm connecting from, the sequences of some keys differ (e.g. F1 is either ^[[11~ or ^[OP). How should I name the zkbd files in order to distinguish between the different mappings?
Rather than simply use TERM=screen, the screen program has a feature which you could use to set different values of TERM. This assumes that you've installed a complete ncurses terminal database, and use a TERM outside screen that corresponds to the actual terminal. For a given TERM, if there is a corresponding "screen.$TERM" entry in the terminal database, then screen will use that. The ncurses terminal database has several of these, to match the actual behavior of terminals that set TERM=xterm, e.g., screen.Eterm, screen.gnome, screen.konsole, screen.konsole-256color, screen.linux, screen.mlterm, screen.mlterm-256color, screen.mrxvt, screen.putty, screen.putty-256color, screen.rxvt, screen.teraterm, screen.vte, screen.vte-256color, screen.xterm-256color, screen.xterm-new, screen.xterm-r6, screen.xterm-xfree86. Once you've setup things to use the terminal database, there's no need for special/magic configuration files of your own. Besides, how would you tell the server which file to use? The real information is on your client, where you know which terminal emulator you are actually using. zsh lets you use this information directly with the $terminfo array. Further reading: Why not just use TERM set to "xterm"? Keybindings (see discussion of $terminfo[])
How to setup zkbd (zsh keyboard bindings) in a server?
1,404,212,370,000
I am running emacs in daemon mode and I got dissconnected from the server on which it was running. After re-connect, when I run emacsclient -nc I get the error connect localhost port 6012: Connection refused ERROR: Display localhost:12.0 can't be opened The daemon still seems to be running, but I can't figure out how to connect to it, any suggestions? Other fun facts, which may or may not be relevant: I am connected through a screen session to a head node and then to another side node of a server. I have been running this setup for a few days and usually I am able to re-connect without problem. I'm sure I could just restart the daemon but I'd like to recover the working session as it is connected to a running matlab job, which I am interfacing with through matlab-emacs. Edit: I tried Gilles suggestion and am still running into problems echo $DISPLAY returns localhost:18.0 I went go into the screen session and ran export DISPLAY=localhost:18.0 and even ran echo $DISPLAY again inside of the screen session localhost:18.0 Now emacsclient -nc returns ERROR: Display localhost: 18.0 can't be opened which is now the same display being used in the machine running the screen session, but still there is no connection. Note that I tried also with export display=localhost:18 edit2: A note about my system architecture My laptop, in my office is connected via ssh to a server 'host1'. host1 has a number of node computers. I first create, or log into a screen session screen -S ohnoplus-five and then connect to node005 with ssh node005 I then detach from screen without logging out of node005 and re attach with screen -r ohnoplus-five from host1 In response to Gills suggestions, I have run export DISPLAY=localhost18.0 which is the the display returned by echo $DISPLAY on host1, not my local laptop.
Remote GUI (X11) connections go through TCP port 6000+n where n is the display number¹. So the two messages refer to the same problem: some program tried to connect to display 12 and failed. Emacsclient doesn't make X11 connections, Emacs does. So if you see this message, it means Emacsclient managed to contact Emacs and tell it to open a new frame. Emacsclient requests a GUI frame if it thinks that an X11 display is available, and a terminal frame otherwise. When the DISPLAY environment variable is set, Emacsclient thinks an X11 display is available. The DISPLAY environment variable is set automatically by SSH when it's forwarding an X11 connection back to your local machine. But when you attach to an existing Screen session, you get the environment that was set inside the Screen session, including the DISPLAY variable. If you disconnect and reconnect, there's no guarantee that the display number is the same². To update the DISPLAY variable, detach from the Screen session, run echo $DISPLAY to see the value set by SSH (e.g. localhost:13), then reattach to the Screen session and run export DISPLAY=localhost:13 (or whatever the correct number is). If you have multiple windows in the Screen session, you'll need to do it in each of them. If you create new windows, type Ctrl+A : setenv DISPLAY localhost:13` Enter to set the environment variable in Screen itself, for the sake of the new windows. If you prefer, you can open a terminal frame by unsetting DISPLAY or by running emacsclient -nw. ¹ SSH uses display numbers starting from 10, leaving numbers 0–9 alone for local displays. In a typical situation, display 12 means that this is the third GUI connection that was opened over SSH. ² In fact, if you got disconnected due to a network problem but reconnected soon after, it's quite possible that the remote machine hasn't noticed the network problem yet — all it knows is that it's been a while since the client sent anything, but that's just normal inactivity — in which case display 12 is still in use as far as the remote machine is concerned. If you have multiple SSH hops, and the connection from the local machine to the intermediate machine is interrupted and resumed, then upon resuming, the display number on the intermediate machine has changed, but the SSH connection from the intermediate machine to the final machine still forwards the original display number. In this scenario, it would be simplest if you ran Screen only on the final machine, and used the intermediate machine as a proxy. Add Host node[0-9]* ProxyCommand ssh -W %h:%p host1 to your ~/.ssh/config and run ssh node005. Then you don't have to worry about the intermediate machine. If you have to run Screen on the intermediate machine, then you'll have to restart the SSH connection from host1 to node005, after updating the DISPLAY variable. (You could also forward the TCP connection from the old display number to the new one, but that would only work if the old display number hasn't been reused in the meantime.)
emacsclient connection refused
1,404,212,370,000
I have one computer running Debian Wheezy(screen version 4.01.00devel) and another one Debian Squeeze(screen version 4.00.03jw4) and under both of them screen automatically starts another process named screen. For example: init(1)-+-acpid(1926) |-sshd(2139)---sshd(2375)---bash(2448)---screen(6649)---screen(6650)-+-bash(6651)---pstree(6751) According to ps PID 6649 command is screen and PID 6650 command is SCREEN: root@vserver:~# ps -f -p 6650 UID PID PPID C STIME TTY TIME CMD root 6650 6649 0 11:26 ? 00:00:00 SCREEN root@vserver:~# Why does screen behave like this?
The outer screen (PID 6649) connects to the terminal you started from, and is terminated when you detach (Ctrl+a,d). The inner screen (PID 6650) is not connected to that terminal, but rather controls its own pseudo-terminal (pty) device, to which the bash started from it is connected. What happens is that when you enter something on the outer terminal, the outer screen gets it, sends it over a socket to the inner screen, and that in turn forwards the input to the pty it controls, so it ultimately reaches bash (or any other program started from bash, and controlled through the same pty). Output from bash (or any program started from it) will be sent to the inner screen's pty, which causes the inner screen sent it through the socket to the outer screen, which ultimately sends it to the terminal you started screen from (which in your case is again a pty created by ssh). Note that the socket is controlled by the inner screen, which allows detaching and re-attaching (see below). If you detach the screen instance, what happens is that the inner screen, and with it the pty it controls, continues to exist. This is why the processes connecting to it, will survive, even if they try to do I/O. However the outer screen will terminate, thus breaking the connection with the outer terminal. You can now for example terminate the ssh session, and thus destroy the corresponding pty, and it will not affect the inner screen nor the programs started by it, since they communicate through their own pty device. If you now log in again (creating another pty), and then call screen -r, the newly created screen instance will be connected to the terminal you started it from (which is completely separate from the one the first instance was started from, since you destroyed that), and then use the socket provided by the inner screen instance to re-connect with the inner screen, which will then send the current state of its own pty to the "outer" screen to display again; afterwards, the same I/O transmission line happens as with the previous outer screen instance. If you now do a pstree, you'll find two lines with screen: One starting at sshd and ending at the new "outer" screen instance, and one starting with the "inner" screen instance which now no longer has a parent since that terminated when you detached the screen. So in short: The "outer" screen (PID 6649) connects with the terminal you're interacting with (in your case, the pty set up by ssh) and only lives as long as you're attached to the screen instance. The "inner" screen (PID 6650) provides a separate pty for the programs you start under screen, and also provides the socket used to communicate the terminal state between the outer and the inner screen instance. It lives until you terminate screen (as opposed to detaching). The separation is necessary to allow the controlled programs to survive the death of the outer pty (by being connected to a different pty which along with its controlling process — the inner screen — survives detaching from the outer terminal), as well as to re-attach (by having the surviving inner screen provide a socket to which new instances of screen can connect).
Why there are two sequential screen processes?
1,404,212,370,000
Here is what I am trying to do: open Gnome terminal launches with my command prompt ssh into work via VPN launch screen create two screen windows try to use F3 and F4 as "prev" and "next" with no luck. try to use F6 and F7 as "prev" and "next" works fine. Here is my .screenrc hardstatus on hardstatus alwayslastline hardstatus string "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G} %H %{..Y} %m/%d %C%a " defscrollback 5000 startup_message off #bind uppercas x to remove region bind X remove bind ^X lockscreen # Bind F3 and F4 (NOT F1 and F2) to previous and next screen window bindkey -k k3 prev bindkey -k k4 next # Bind F5 to switch to next focus bindkey -k k5 focus bindkey -k k6 prev bindkey -k k7 next #split window bindkey -k k8 split bindkey -k k9 remove What's strange is the following works: Works 1: Doing this via putty works fine Works 2: using the exact same .screenrc works fine if I am on my local machine Doesn't work: using lxterminal has the same issue My thoughts are that ssh may be causing this but not sure. EDIT: Here are the outputs of some terminal related commands: Local Machine: $ echo $TERM xterm $ infocmp -1 | grep kf.= kf1=\EOP, kf2=\EOQ, kf3=\EOR, kf4=\EOS, kf5=\E[15~, kf6=\E[17~, kf7=\E[18~, kf8=\E[19~, kf9=\E[20~, Work Machine: $ echo $TERM xterm $ infocmp -1 | grep kf.= kf1=\EOP, kf2=\EOQ, kf3=\EOR, kf4=\EOS, kf5=\E[15~, kf6=\E[17~, kf7=\E[18~, kf8=\E[19~, kf9=\E[20~, Work Machine using screen: $ echo $TERM screen $ infocmp -1 | grep kf.= kf1=\EOP, kf2=\EOQ, kf3=\EOR, kf4=\EOS, kf5=\E[15~, kf6=\E[17~, kf7=\E[18~, kf8=\E[19~, kf9=\E[20~,
I think I know what it is. xterm used to send different escape sequences for the F1 to F4 keys. From the xterm documentation: Older versions of xterm implement different escape sequences for F1 through F4. These can be activated by setting the oldXtermFKeys resource. However, since they do not correspond to any hardware termi- nal, they have been deprecated. (The DEC VT220 reserves F1 through F5 for local functions such as Setup). screen used (and you've got quite an old versions, though we would blame you as the newer ones are not official releases) to come with a default /etc/screenrc with: termcapinfo xterm 'k1=\E[11~:k2=\E[12~:k3=\E[13~:k4=\E[14~' That is that tell screen that F1 -> F4 are actually what they used to be in ancient xterms. You should comment out that line in your /etc/screenrc, so that screen takes it from the terminfo/termcap database as expected.
How do I fix this strange behavior with ssh, gnome terminal and gnu screen where function keys F1 through F4 are not accepted?
1,404,212,370,000
I use Screen with a lot (more than 10) of local Bash sessions inside. I send some processes (like vi file) to the background and switch between sessions very often and sometimes it's very annoying to find out where the file I have to edit is being already opened. Is there a way to share such background processes to be able to access it from any Bash sesssion inside this screen?
No, the documentation for bash job control doesn't mention any support for sharing or adopting jobs between different bash sessions. However, reptyr will allow you to take control of a job that was backgrounded in another session, which might be close enough to what you want. reptyr requires the pid of the job you want to take over, so you have to find that pid first. You can decide for yourself whether this is more work than just finding the original screen window. It sounds like you're mostly interested in doing this with vim (yes, you said vi, but I'm assuming vim is what you're running under the hood). vim -r will give you a list of all open vim sessions, along with files they are editing. Read the list, find the pid that's using the file you want, and run reptyr <pid>. To be thorough, vim won't stop you from just editing a file that's already open elsewhere - using vim -r <filename> - but remember to reload the file again with :e when you return to the original session, so your new edits are applied to the latest version. vim will remind you about this on certain events.
Share background jobs between shells
1,404,212,370,000
I have a shell program in Ubuntu 16.04, named foo, that outputs status update when I press any button. It's located in /usr/local/bin/foo, so I can call the program anywhere. The program works like this: $ foo Welcome after I press a key, it will show: Time now is 01:23:45 If I press Ctrl-C, it will exit just like most of the other shell programs. I would like this foo program to be run in multiple instances. I know GNU Screen command can switch between tasks, but is it the correct way to do so? Alternatively, I know that I can put the program to run in the background like this: $ foo & [1] 123456 Job ID 1 is created in the background and I can call it out by its Job ID: $ fg %1 However, I need to put it back to background after obtaining the latest output of the program (by pressing any button: is there any method to do this programmatically?). How can I achieve this?
From what I can see, your requirements are to be able to: Run several instances of the program concurrently. Get terminal control over any of the instances at any time. Send instances back to background as soon as they output. If we stick to the & approach, then yes, there is a shortcut for (3). When a program has control over a terminal, it can be sent to the background using a SIGTSTP signal. Conveniently enough, that's usually what Ctrl + Z does. You could therefore have something like this: $ foo & Welcome [1] 10 $ foo & Welcome [2] 11 $ fg %1 <ENTER> Time now is 01:23:45 <Ctrl+Z> [1]+ Stopped To my knowledge, there is no such shortcut for fg (and how would you indicate which instance to bring back anyway?) Note that the SIGTSTP signal does not actually need to come from the shell which started the process. If you kill -TSTP the process by PID in a second shell, you'll also be able to get it back with fg in the first. I need to put it back to background after obtaining the latest output of the program (by pressing any button: is there any method to do this programmatically?) If by programmatically you mean that you have access to foo's source code, then you can use what we've just seen. The raise system call can be used by a program to send itself a signal. If we take a very simplistic version of foo, we can have something like this: #include <stdio.h> #include <signal.h> int main(void) { printf("Welcome"); while(getchar()) { /* Use termios to switch to unbuffered mode */ fprintf(stdout, "The time is... something"); fflush(stdout); fflush(stdin); raise(SIGTSTP); } return 0; } Now while this is all reasonably nice, I would agree that screen is probably a nicer way to do all this, mostly because you can name your screen sessions and therefore never need to remember a job or process ID. Just like the & approach, it also has the advantage of not requiring changes to the source code. $ screen -S foo1 $ ./foo Welcome <Ctrl-a d> [detached from 10.foo1] $ screen -s foo1 <ENTER> Time now is 01:23:45 <Ctrl-a d> [detached from 10.foo1] Another advantage here is that you do not need to stop your program before detaching. That's pretty convenient if you want it to do stuff in the background while you're not looking. In the previous approach, you would need to run bg every time you stop foo. You can also get a list of running screens with screen -ls. On my machine, I've setup a few aliases in ~/.bashrc to account for my extra laziness: alias S='screen -S' alias s='screen -r' alias sls='screen -ls' This way you could simply do things like S foo1, s foo1, ... Some might argue than one-character aliases can be a little annoying when you misplace a space or something in your commands, but I think screen is one of those programs which are so convenient that you can afford to make an exception. Now assuming you're going with the screen approach, here's how you could send a key to a session and fetch its last line of output from a shell. There are ways to tweak this (and I've allowed myself some shortcuts) but anyway. You can define the following function in ~/.bashrc : screen_key_tail() { screen -S $1 -X stuff "^M" tmp="$(mktemp)" screen -S $1 -X hardcopy "$tmp" grep -v ^$ "$tmp" | tail -n1 rm "$tmp" } and call it with: $ screen_key_tail foo1 where foo1 is the name of the screen session you're targetting.
Multiple instance of same program, obtaining output
1,404,212,370,000
I am in a bit of a tricky situation where I need to connect to a server via SSH through a Jenkins plugin. There is no option to pass in the -t flag and get myself a pseudo-tty session so I can use screen. Is there anyway to get around this once already connected besides establishing a nested SSH session?
If you want to use screen to display something, you will need a terminal. If you only want to start a new session, but not display it, invoke screen -m -d. The session starts out detached. If you only want to interact with an existing session, use the -X option to send a command to that session. This doesn't attach to the session and doesn't require a terminal. Note that if a screen session was started in detached mode, its initial window is not active, so you'll probably need to select the window with -p before doing anything, e.g. screen -d -m long-running-command screen -p 1 -X stuff 'yes^M' Whatever you do you'll probably want to use a reproducible session name and always pass the -S option so you know which session you're talking to.
Possible to use screen via ssh without -t?
1,467,401,272,000
I don't have control over the shell prompt or preexec, and I want to keep the titles I assign to screens. Can I get screen to ignore title-escape-sequences?
If you have a terminal whose description "looks" like xterm, screen assumes it does everything like xterm. For whatever reason, it equates xterm-titles and xterm-mouse features: in termcap.c, it checks if either the TERM environment variable contains the string "xterm" or "rxvt" — or it checks if there is a key definition for kM with the xterm-style \033[M string. if that check fails, (follow the D_CXT symbol in ansi.c and display.c), screen suppresses the escape sequences for the mouse and for the title. So you can do it, but probably not as you want: you could set TERM to vt100 (and screen wouldn't know about the mouse — or the title strings). If you are really ambitious, you could modify screen, to make the two features separately configurable.
How do I stop title-escape-sequences from clobbering my GNU screen titles?
1,467,401,272,000
I'm using Ubuntu 14.04. I know how to get my screen resolution using xrandr or xdpyinfo. But with these tools I get the maximum available desktop size .... I have a menu bar at the top that takes some of the available desktop. I have a launcher on the left that takes some of the available desktop. How can I find the real available desktop size using a bash script that accounts for the space used by the menu bar and launcher?
After much searching I found the xprop command which returns the information I was looking for. available_screen=$(xprop -root | grep -e 'NET_WORKAREA(CARDINAL)') #get available screen dimensions available_screen=${available_screen##*=} #strip off beginning text current_screen_width=$(echo $available_screen | cut -d ',' -f3 | sed -e 's/^[ \t]*//') current_screen_height=$(echo $available_screen | cut -d ',' -f4 | sed -e 's/^[ \t]*//')
get available screen size after considering space used by the menu bar and launcher
1,467,401,272,000
I wan't to be able to copy-paste the contents of my screen scrollback buffer into various browser text fields, usually when pasting an excerpt from a log file. One way that works well is the following: $ xsel -bi <CTRL-A ]> Enter <CTRL-d> Then simply pasting into the browser with CTRL-v. This works well for short excerpts of text. The problem is that these log excerpts often exceed 4 kilobytes, perhaps reaching 16k or 32k at a maximum. This causes CTRL-v to hang in the browser, perhaps due to the issues raised in the following two questions: http://unix.funmontage.com/questions/204815/terminal-does-not-accept-pasted-or-typed-lines-of-more-than-1024-characters# http://unix.funmontage.com/questions/131105/how-to-read-over-4k-input-without-new-lines-on-a-terminal I tried the solutions suggested in the answers to these questions to no avail. Is there any other way of getting around the 4k buffer limit?
If you don't mind using a temporary file, you could do: C-a : writebuf filename $ xsel -bi < filename
Copy a large (over 4k) selection of text from the screen scrollback buffer into the system clipboard
1,467,401,272,000
I have fedora 20; after last update, when I am using screen command, the terminal is closing instantly with message: [screen is terminating] and not letting me to do anything with normal user, but from root account everything is fine. Any ideas what is wrong? this is from root account, after typing "screen": and this is when im typing "exit" after:
I hit the same thing. It seems to be caused by the following bug: https://bugzilla.redhat.com/show_bug.cgi?id=884673 # mount | grep devpts devpts on /dev/pts type devpts (rw,relatime,mode=600) Remounting /dev/pts with proper permissions helped me: mount -o remount,gid=5,mode=620 /dev/pts And of course editing /etc/fstab.
fedora 20 screen command terminating automatically
1,467,401,272,000
I once used a server where using the screen command gave me a colorful header which told me the name of the screen, the total number of screens, the runtime, cpu utilization and maybe some hotkeys to cycle between the instances. How can I achieve this header on my Ubuntu Precise Pangolin server instance (I have admin rights)? As it is, I don't even see if I'm inside a screen or not.
You need to modify your ~/.screenrc if you don't have one you can copy it with: cp /etc/screenrc ~/.screenrc and then add the following line. caption always "%{rw} * | %H * $LOGNAME | %{bw}%c %D | %{-}%-Lw%{rw}%50>%{rW}%n%f* %t %{-}%+Lw%<" You can change the caption to your personal needs. Therefor you should read the GNU Screen manual especially the string escape chapter. An alternative to GNU Screen is Byobu, it is an already configured Screen, may be you should take a look at it, if you want GNU Screen. You can install it with sudo apt-get install byobu And of cause there is tmux which is like GNU Screen with less glitches and it always shows a caption. But tmux has different key bindings and if you are used to screen you will need some time to adapt. You can install it with sudo apt-get install tmux
How to see screen information at the top of terminal?
1,467,401,272,000
I'm using screen with a hardstatus listing my open windows, I usually have a few named (mail, im, top, etc.) and a few with blank name. Some program changes the current window name, for my named window that's not a problem: Ctrl+a, A: allow me to change back the name. but the same command does not want an empty string as the name and keep the current name in that case. So, how can I set an empty name to screen window? A single space does not count.
Invoke the screen colon command with Ctrl+a, : and enter the command title "".
clear gnu screen window name
1,467,401,272,000
Overview of UTF8 screen re-attachment issues. Problem: Creating a screen that uses UTF8 works perfectly until re-attaching said screen session. Steps: ssh remothost screen -U -S ttytter [detach screen] [exit ssh] xterm -class 'xterm-ttytter' -geometry 175x20 \ -title 'ttytter' -e ssh -t remotehost "screen -dU -r ttytter" Details I am a really big fan of ttytter and have been using it for some time now. I have recently started using xterm vs xfce4-terminal/gnome-terminal as I find it is much cleaner. I am trying to use UTF8 for personal and professional reasons and I am still trying to work out a few bugs. The initial attachment (creation) gives me UTF8 input that works like it should. $TERM is xterm-256colors while $LANG is en_US.UTF-8. This is also true once I re-attach the screen, although I am unable to use certain characters, such as backspace, which shows up as ^H. It seems that the issue is specific to the command I am issuing to re-attach the screen. I am trying to figure out what it is that could be causing such an issue when I re-attach my UTF8 screen. I have tried -dr and -dU -r, both of which are failing to solve my problem. I have tried giving xterm the -u8 flag, giving me no change in behavior. xterm -class 'xterm-ttytter' -geometry 175x20 \ -title 'ttytter' -e ssh -t remotehost "screen -dU -r ttytter" The above causes problems. ssh remotehost screen -dU -r ttytter The above works just fine. Settings .screenrc defc1 off defutf8 on utf8 on .Xdefaults xterm*utf8: 1 .bashrc export LANG=en_US.UTF-8 I will really appreciate any guidance on solving this issue.
Solution Different 'classes' load different configuration files from /etc/X11/app-default/. My problem was that my new xterm class did not have a matching configuration file. # cd /etc/X11/app-default # ln -s XTerm-color xterm-ttytter The above will link XTerm-color's class settings for xterm-ttytter by creating a symbolic link. This way, any changes that are made to XTerm-color will automatically be applied to xterm-ttytter as well. Credit goes to @Nei on Freenode/#xterm for explaining program classes for X11.
Resuming screen with UTF8 enabled breaks character input
1,467,401,272,000
I have my gvim setup so that I can select word-wise with Ctrl-Shift-Right, Ctrl-Shift-Left etc. (yes, I know it's a bad habit, but it works for me..). Unfortunately, these key combinations delete text when used in console vim inside a screen session. I believe this is because the two key combinations produce the codes Esc[1;6D and Esc[1;6C on the terminal, which are interpreted as "delete next 6 lines" or "change next lines", respectively. Is there some way to stop screen or console vim from interpreting these key combinations? UPDATE: Content of my .screenrc: sessionname daku startup_message off hardstatus on hardstatus alwayslastline hardstatus string "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G} %H %{..Y} %m/%d %C%a "
Clearly Vim doesn't have a binding for the key sequence ␛[1;6D but has one for some other key sequence that begins with ␛[1, probably ␛[1~ (usually sent by the Home key). Add remappings to your .vimrc to declare that ␛[1;6D is really Ctrl+Shift+Left and so on. I think the following should do the trick: noremap <ESC>[1;6D <C-S-Left> noremap! <ESC>[1;6D <C-S-Left> noremap <ESC>[1;6C <C-S-Right> noremap! <ESC>[1;6C <C-S-Right> Here's what I have in my .vimrc: function Allmap(mapping) execute 'map' a:mapping execute 'map!' a:mapping endfunction function Allnoremap(mapping) execute 'noremap' a:mapping execute 'noremap!' a:mapping endfunction call Allmap('<ESC>[6D <C-S-Left>') call Allmap('<ESC>[6C <C-S-Right>') call Allnoremap('<C-S-Left> <C-Left>') call Allnoremap('<C-S-Right> <C-Right>')
console vim in screen session: remap Ctrl-Shift-Left, Ctrl-Shift-Right to not delete lines
1,467,401,272,000
I managed to replace the audible bell by a visual clue in the active window, but for background windows, can I get an audible bell instead of a visual notification ?
Redefine "bell_msg" to include a literal "^G". (That is, the two characters carat and Capital-G.) From the screen manpage: bell_msg [message] When a bell character is sent to a background window, screen displays a notification in the message line. The notification message can be re-defined by this command. Each occurrence of `%' in message is replaced by the num­ ber of the window to which a bell has been sent, and each occurrence of `^G' is replaced by the definition for bell in your termcap (usually an audible bell).
How can I have screen transmit an audible bell produced in a background window?
1,467,401,272,000
Is it possible to divorce my input from the overall shell using Screen? What I'm aiming for is akin to a status line that expands if I type more than would fit within a single line and is 'submitted'/'sent' to the shell when I press enter. I'm looking to put together a simple configuration to use as a MUSH/MUD/MUCK/MOO client using screen+telnet. The current issue with using telnet is that data sent from the remote server is inserted at the cursor position, which sucks badly if you're typing a lengthy paragraph.
A good architecture would be to divide the screen into two windows, one for command input and one for program display. That's basically what a normal MUD client would do. You can do that in Screen with the split command (C-a S). Create a named pipe to transmit your input from the input window to the telnet window: mkfifo mud-input-fifo. In one of the windows, run telnet mud.example.com 1234 <mud-input-fifo or nc mud.example.com 1234 <mud-input-fifo (nc is netcat, the Swiss Army knife of networking). In the other window, run rlwrap tee mud-input-fifo (rlwrap provides line edition to any line input program). Emacs could do that too. But you'd end up implementing a MUD client in Emacs, which has been done before (mu.el, mud.el, mudel.el, eMUDs, …).
Divorced input line in GNU Screen
1,467,401,272,000
When I'm in a gnu screen I can split horizontally (or vertically) and start a terminal session in the new region. If I detach from this screen with Ctrl-a,d and then resume, now I just see the second region of the split in the entire window. I know the first region is still there somewhere because if I type exit in the second region then the first session shows up and I can type exit again to actually close end the screen session. How can I resume a screen with a split into regions and actually get my splits all visible at once? An easy way to reproduce this issue: $ screen -S splitresume $ export PS1="region 1$ " <Ctrl-a |>, <Ctrl-a TAB>, <Ctrl-a c> $ export PS1="region 2$ " <Ctrl-a d> $ screen -r splitresume At least on my system, after screen -r splitresume I only see the prompt with region 2$. As I said above, If I exit that terminal session, I can now see the terminal with the regsion 1$ PS1. I'd like to be able to resume and have the regions sredrawn in some visible space as well. EDIT: I tried with the resize command, but the response from screen is just a complaint: resize: need more than one region.
See GNU Screen FAQ When I split the display and then detach, screen forgets the split. (The implied question being, “How do I keep my split windows over a detach?”) The short is answer is that you can't. The longer answer is that you can fake it. (Note: the next screen release, probably numbered 4.1.0, will be able to remember display layouts.) Splits are a property of your display. The process managing your screen session doesn't really know about them; only the single process that's displaying the session does. Thus, the screen session can't remember the splits because it doesn't know about them, and once you detach, the process that did know about them has exited. The hack is to use nested screen sessions. Start one session and give it some escape sequence that you won't use much (or just disable its escape character completely). Bind your usual detach key sequence to this screen session. Now, start or attach to your main screen session. All of your work will be done in the inner session, and you can split your display. When you detach, however, it will be the outer session that detaches, so your splits in the inner session will be preserved. Assuming you use the default escape character, C-a, your alternate screenrc should contain: escape "" bindkey ^ad detach
resume gnuscreen with split area
1,467,401,272,000
I'm trying to create a script that runs in terminal is automatically started in a raspberry pi 'screen' output. The problem here is that I need sudo privileges inside the script, and that once the process is running I don't see the request for the password. One example of the script is the following (if I get this to work I can adapt the script for other purposes): 1) go to a folder: cd /etc/openvpn 2) execute the service (this requires sudo privileges): sudo openvpn ./pia_netherlands.conf When I enter the code manually the script does run so there is no problem there, I just have a problem executing this inside a 'screen'. I've set up the following script using some googling: #!/bin/sh if [ -z "$STY" ]; then exec screen -dm -S pia /bin/bash "$0"; fi cd /etc/openvpn sudo openvpn ./pia_netherlands.conf This script should check if there is a screen called 'pia' and if not create a screen called pia and run the script by firstly going to the folder and then run the openvpn file. I've tried a second script that is a bit more straightforward but this also doesn’t work: sudo bash screen -S pia cd /etc/openvpn openvpn ./pia_netherlands.conf This script opens a bash screen called 'pia', goes to the folder, and executes the openvpn file. Both methods are not working, and I really have difficulties finding out how to get it to run. Can anyone help me please? I've also consulted the raspberry pi forums but no one replied, I guess because this is more of a linux question than a raspberry question.
If I read the man page correctly, openvpn can act as a daemon (i.e. go to the background itself) with the --daemon switch. So if you don't need screen specifically, you might be able to go with: sudo openvpn --daemon --config /etc/openvpn/pia_netherlands.conf Some other alternatives: start screen to run the script, enter the password, then detach the screen. run the whole screen under sudo, instead of just the openvpn? i.e. sudo screen -S pia openvpn /etc/openvpn/pia_netherlands.conf add the script to /etc/sudoers with the NOPASSWD: flag, so you can run that particular command without entering the password every time.
Run script using 'screen' with sudo privileges
1,467,401,272,000
I want to share a screen session, but this is harder then it seems for me. What I did was yum install screen then I made a session with root screen -S test. After that i made it multiuser Ctrl+A :multiuser on. I started a new SSH connection logged in as Foo and did screen -ls. All I get is there is no socket at /var/run/screen/S-foo/. I also export the SCREENDIR to /var/run/screen/ so it is only one DIR where the sessions are saved in. But the system don't allow for other user to own it.
Since your user doesn't actually own the session it won't show up when using screen -ls. You need to use :acladd <username> and then to attach screen -r root/test more info
How to share GNU Screen sessions
1,467,401,272,000
I have about 15 instances of screen running on my linux server. They are each running processes I need to monitor. I had to close terminal (hence the reason I launched screen). Is there a way to reopen all 15 instances of Screen in different tabs without having to open a new tab, login to the server, print all the available screens to resume, and then type in the id for each screen session?
This python script just did the job for me. I made three screen sessions and this fires up three xterms with the sessions reattached in each. It's a bit ugly but it works. #! /usr/bin/env python import os if __name__ == '__main__': tempfile = '//tmp//screenList' # capture allthescreenIds os.system('screen -ls | grep Det | cut -d . -f 1 > ' + tempfile) f = open(tempfile, 'r') screenIds = f.readlines() f.close() screenIds = [x.lstrip() for x in screenIds] for eachId in screenIds: cmdLine = 'xterm -e screen -r ' + eachId.strip() + ' &' os.system(cmdLine)
How to resume multiple instances of Screen from command line with minimal steps?
1,467,401,272,000
I run a console window through my PuTTY session. That console windows has a column width of 140. When I start the screen session, the console shrinks to 80 columns. I do not see this behavior on CentOS 5, only on CentOS 6. Does anybody know what has to be tweaked?
Sorry, forgot to answer with my own solution to this problem. Turns out CentOS 6 disables this line in its /etc/screenrc script: termcapinfo xterm Z0=\E[?3h:Z1=\E[?3l:is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;4;6l I was able to restore the functionality by putting this line into my local ~/.screenrc file. Here is the content of my ~/.screenrc file in its entirety # Fix termcapinfo for xterm to allow column resizing # xterm emulation is used by PuTTY termcapinfo xterm Z0=\E[?3h:Z1=\E[?3l:is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;4;6l If you are a sysadmin, you may want to put this .screenrc file into /etc/skel directory, and home directories of existing users.
Why CentOS 6 adjusts console width when running screen?
1,467,401,272,000
Sometimes the SSH shell featuring a active screen session to my remote server gets broken (internet line not very stable, for example) with the session still attached. Then I SSH again into the server, and try to resume the screen session: luis@Zarzamoro:~$ screen -r There is a screen on: 9166.pts-2.Zarzamoro (12/23/15 23:47:34) (Attached) There is no screen to be resumed. luis@Zarzamoro:~$ screen -r 9166.pts-2.Zarzamoro There is a screen on: 9166.pts-2.Zarzamoro (12/23/15 23:47:34) (Attached) There is no screen to be resumed matching 9166.pts-2.Zarzamoro. I don't know much about GNU screen. Why does this happen? Is it possible to resume this screen session?
Two points: You do not have to specify the whole pid+session name (screen accepts a reasonable abbreviation). You may get better results with the -x option. From the manual page: -r sessionowner/[pid.sessionname]’ Resume a detached screen session. -x Attach to a session which is already attached elsewhere (multi-display mode). Screen refuses to attach from within itself. But when cascading multiple screens, loops are not detected; take care.
GNU Screen: can not resume the screen from a broken remote session
1,467,401,272,000
I am working on an HPC with LSF job system. screen works fine on logon node and most of the computation nodes which I can ssh into them. which command shows that screen is located under /usr/bin. But I found on some node, bash just can not find screen, and mysteriously, I can not find screen under /usr/bin on that node. But I have to use it. So I think maybe I can install a local version of screen, so I download the screen-4.5.1.tar.gz package. However, ./configure terminated with error configure: checking for tgetent... configure: checking libcurses... configure: checking libtermcap... configure: checking libtermlib... configure: checking libncursesw... configure: checking libtinfow... configure: checking libncurses... configure: checking libtinfo... configure: error: !!! no tgetent - no screen Google shows that we need to either sudo apt-get install libncurses-dev or sudo apt-get install ncurses-dev. However, I am not administrator and I have no internet connection on HPC. So I think manually install ncurses should be fine. I downloaded ncurses-6.0.tar.gz. configure, make, make install, finally I got 4 folder in my custom folder myInstall_ncurses: bin, lib, include, shared. But How should I install screen now? I tried this ./configure --bindir="/home/myInstall_ncurses/bin" --includedir="/home/myInstall_ncurses/include" --libdir="/home/myInstall_ncurses/lib" But the error is the same. What is wrong?
If you have ncurses installed in /home/myInstall_ncurses, and there are lib and include subdirectories of that: export LDFLAGS='-L/home/myInstall_ncurses/lib' export CPPFLAGS='-I/home/myInstall_ncurses/include' ./configure --prefix='/where/to/install/screen' make make install
Can not find screen and how to install it without network and administration?
1,467,401,272,000
When I ssh to a server and start a script that is supposed to run for several days, it stops executing some time after I log off. Why? I suppose the server runs 24/7. And what does screen/tmux do to prevent this from happening?
From an operating system's point of view, every running program is a process. When the kernel is done initializing it will start one process, mostly init. Whether it is SYSV init or systemd is not relevant for this discussion, one process is started. Every other program is started by another process. This creates a relationship between processes, the starting process (a.k.a. "parent") and the started process (a.k.a. "child"). The kernel is aware of these relations. When a process exits in Linux/Unix, the kernel sends to all its child processes the signal number 15 (SIGTERM). It can be caught by the process and the process should do whatever it has to do to exit in a safe way. You may know also know the signal number 9 (SIGKILL). This signal cannot be caught by the process: the kernel stops the process by itself. See this pstree: init─┬─acpid ├─atd ├─cron ├─dbus-daemon ├─dhclient ├─dhcpd ├─exim4 ├─6*[getty] ├─lwresd───6*[{lwresd}] ├─named───6*[{named}] ├─nmbd ├─portmap ├─rpc.statd ├─rsyslogd───2*[{rsyslogd}] ├─smbd───2*[smbd] ├─sshd───sshd───bash───screen───screen───bash───pstree └─udevd───2*[udevd] You can see that pstree is a child process of bash, and bash a child process of screen. When I logout from the machine, the bash after sshd exits and the kernel sends a signal 15 to the child process screen. BUT, screen doesn't react to this. So screen's new parent process is now process number 1 (init). See in this pstree: init─┬─acpid ├─atd ├─cron ├─dbus-daemon ├─dhclient ├─dhcpd ├─exim4 ├─6*[getty] ├─lwresd───6*[{lwresd}] ├─named───6*[{named}] ├─nmbd ├─portmap ├─rpc.statd ├─rsyslogd───3*[{rsyslogd}] ├─screen───bash ├─smbd───2*[smbd] ├─sshd───sshd───bash───pstree └─udevd───2*[udevd] In fact, this is what happens when you detach the screen (ctrl+a - d). So all sub-processes of screen keep running after disconnecting or detaching from screen. When you run a process without screen or tmux, it will get a SIGTERM signal.
Why do you need screen/tmux to keep a remote program running
1,467,401,272,000
Whenever I use the script command to record the keys I type or when I activate the logging mode in screen, all BS (Backspace) and ESC (Escape) key presses are also included in the file. e.g: cd ~/foo/tpBSBStmp. Is there a way to auto remove the BS or the ESC from the file so the final recorded command included in the file would be cd ~/foo/tmp? Btw, this also happens in the logging feature of Putty. I'm open to any scripts that remove the unwanted characters or even another commands that do the same job
The output of script will always contain linefeeds, backspaces and ANSI escape sequences as stated in the manpage. Examples of programs that will correctly display all these are cat and more. cat typescript and more typescript will display typescripts exactly as it looked when you recorded them. If you still want to clean the typescripts, take a look at this script. It is a Perl script I stumbled upon some time ago that is made specifically for cleaning up typescripts made with script. Try it by running script-declutter myTypescript > cleanTypescript Edit: Not really related to the answer, but you might be interested in TermRecord. It creates neat, self contained HTML and Javascript representation of your terminal sessions so that anyone can view them without any knowledge of how to handle typescripts. All they need is a web browser.
Remove BS and ESC from Log files
1,362,151,169,000
Further to my previous question on screen not splitting my terminal , I got to the point where I can split my terminal horizontally but not vertically . This documentation says that vertical splitting requires screen >= 4.1. So how can I find out which version of screen I am using?
Type Ctrl-A then v. You'll get something on the status line that looks like screen 4.00.03jw4 (FAU) 2-May-06
How can I find out which version of screen I am using?
1,362,151,169,000
I would like to run a bash scrpit while using a screen session, here is my script : #!/bin/bash for i in 1 5 18 20 do screen -S output_${i} ./run_my_program screen -d The problem is that the screen session does not detach using screen -d (but detach with the keyboard shortcut ctrl-a d), any suggestion ? Thanks.
You don't have to "enter" the screen session to get it to run, just use -dm and it will start the session in detached mode: for i in i 5 18 20; do screen -dm -S "output_$i" ./run_my_program done
Detach from screen session inside bash script
1,362,151,169,000
In ZSH prompt expansion, the command %E is supposed to "Clear to end of line." This works. We see it in the grey bar going all the way across. However, if I call "screen", the %E stops working: Any idea what the cause of this is, and how it can be fixed?
When you send one of the ECMA-48 erase control sequences, whether the erasure uses the current background colour or the default background colour varies amongst different terminal types. (In the terminfo database, there is a capability that allows programs to determine what the terminal that they are talking to will do. It is named bce. The termcap equivalent name is ut.) You are setting the current background colour, and then erasing to the end of the line, expecting the erasure to always use that current colour. screen is a terminal emulator itself. But unlike most hardware terminals its behaviour in this regard is switchable. By default, background colour erase is switched off, and the control sequence causes erasure with the default colour. One switches it on with the bce command. One sets the default for the bce setting in all new screens with the defbce command. (I say most, because late model DEC VTs provide DEC Private Mode 117 for switching the behaviour. The default for these terminals was the "new" PC-compatible behaviour of erasing with the current colour, and switching Private Mode 117 off would revert back to the "old" VT-compatible behaviour of erasing with the default colour. DEC VT 52x terminals were switchable like screen, except that the host could do the switching and the default was the "new" behaviour, the opposite of screen's default. These terminals were actually newer than screen, by several years.) So switch it on. It's as simple as that. Further reading "Character Processing", Screen Users' Manual. GNU Project. "DECECM". VT520/VT525 Video Terminal Programmer Information. EK-VT520-RM. July 1994. DEC. https://unix.stackexchange.com/a/252078/5132
Clear to end of line uses the wrong background color in screen
1,362,151,169,000
I keep a screen session running on a dev box at work, and I ssh into my dev box and resume my screen session while I'm at work. From there, I hop to other machines. Occasionally, I find myself ssh'ing to a remote host from my already-remote-screen-session-over-ssh when that remote host I'm ssh'ed to doesn't allow me to disconnect cleanly. So I end up needing to force my remote (second) ssh session to die without affecting my original ssh session connected to screen. I know that killing ssh is done with a enter ~., but like I said, my local ssh client intercepts that key-combo accomplishing nothing more than my needing to reconnect ssh to my dev box. Anyone ever run into this? How do I terminate the remote ssh session in screen without killing my original ssh session? I'm unable to find anything apropos in screen to do it. This also goes for additional hops IE ssh -> screen -> ssh -> ssh (unable to logout cleanly) <- want to force kill this ssh session. I tried running enter ~~., which kills the second ssh session, and that kind of works. It's not good enough for say a third, fourth, or more hop, though. It would be nice to have a solution that works however deeply nested I am ssh'ed into other machines.
To kill the nth SSH session, type <enter>, then 2^(n-1) ~, then .. (~~ sends the escape character; thus, two tildes will cause the first SSH to send it to the second SSH, which will then pick up the dot and die. Extrapolate as necessary for deeper nesting.) I have a similar situation; my solution is to have Mosh on the dev box, which doesn't pick up SSH's escape sequences (but has its own). This strips one layer from the whole thing, which makes things easier.
ssh -> screen -> ssh - how to kill remote screened ssh without killing original ssh session
1,362,151,169,000
I'd like to run on a list of servers and run remotely a script while using screen. Manually, I'd do: screen -RD ./run_script and manually remotely I'd do: ssh root@server "screen -RD && ./run_script" but what happens in reality is that screen -RD is running and when I type exit only then it starts running the script. So how can it be achieved to run screen -RD remotely and then issue a command within the first screen terminal? Edit #1: [root@edge14 ~]# screen -r -X /nfs/ops/component/edge/scripts/move_stuck_aggfiles_to_hadoop.sh && screen -RD No screen session found. [root@edge14 ~]#
You use the -X switch. From the man page: -X Send the specified command to a running screen session. You can use the -d or -r option to tell screen to look only for attached or detached screen sessions. Note that this command doesn't work if the session is password protected. To combine this with actually seeing the screen: ssh root@server "screen -dr -X ./run_script && screen -RD" (But you really should not allow ssh logins as root, it's very bad practice from a security standpoint.)
How to run a script on a remote machine using the screen command and ssh?
1,362,151,169,000
Is there a way of creating new window in GNU screen with title specified while creating the window itself. I know that I can create a new window and then set the title using ^A A but is there a way of mentioning tilte while creating the window itself.
Short answer: ^A : screen -t title command ^A: brings up the screen prompt, and the rest of the line is a command to create a window with title "title" running command "command". Below is the relevant documentation for the screen subcommand from the screen(1) manpage. screen [-opts] [n] [cmd [args]|//group] Establish a new window. The flow-control options (-f, -fn and -fa), title (a.k.a.) option (-t), login options (-l and -ln) , terminal type option (-T <term>), the all-capability-flag (-a) and scrollback option (-h <num>) may be specified with each command. The option (-M) turns monitoring on for this window. The option (-L) turns output logging on for this window. If an optional number n in the range 0..MAXWIN-1 is given, the window number n is assigned to the newly created window (or, if this number is already in-use, the next available number). If a command is specified after "screen", this command (with the given argu‐ ments) is started in the window; otherwise, a shell is created. If //group is supplied, a container-type window is created in which other windows may be created inside it. Thus, if your ".screenrc" contains the lines # example for .screenrc: screen 1 screen -fn -t foobar -L 2 telnet foobar screen creates a shell window (in window #1) and a window with a TELNET connection to the machine foobar (with no flow-control using the title "foobar" in window #2) and will write a logfile ("screenlog.2") of the telnet session. Note, that unlike previous versions of screen no addi‐ tional default window is created when "screen" commands are included in your ".screenrc" file. When the initialization is completed, screen switches to the last window specified in your .screenrc file or, if none, opens a default window #0. Screen has built in some functionality of "cu" and "telnet". See also chapter "WINDOW TYPES".
GNU Screen: Creating new window with title specified
1,362,151,169,000
I have a few detached screens running. Now I’d like to see their current state for each of them. Currenlty, I do $ screen -r # look at the cryptic numbers $ screen -r <paste number one> # look at output <Ctrl-A> D $ screen -r # look at the cryptic numbers to find the next one $ screen -r <paste number two> # look at output <Ctrl-A> D $ screen -r # look at the cryptic numbers to find the next one # and so on $ screen -r <paste number three> # look at output Is there a single command that lets me do that?
I think time shows that the answer to this question is simply: No, it is not possible.
Display content of all currently detached screen
1,362,151,169,000
I Have recently started configuring "screen", I have included my .screenrc below. I have a problem that if windows 0 & 1 (containing bash) are idle for about 10 mins they will close only leaving window 2 containing irssi. Have I done something wrong? is there something i can do to stop this from happening? I have tried searching for similar problems or solutions but I am finding it difficult to find anything relevant. startup_message off autodetach on shell /bin/bash defutf8 on altscreen on hardstatus alwayslastline hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]' defscrollback 30000 # Default screens screen -t bash-0 0 screen -t bash-1 1 screen -t irssi 2 irssi select 0
Is the TMOUT environment variable set (nothing to do with screen)? If it's set to 600, then bash will close the session after 600 seconds (10 minutes).
Configuring screen, window problems
1,362,151,169,000
I have a ruby terminal script that I would like to print out hyperlinks. I achieve that like so: puts("\e]8;;https://example.com\aThis is a link\e]8;;\a") This works perfectly fine in a "normal" terminal (gnome-terminal btw) window. But I need to run this script within GNU screen, where the escape-sequence simply has no effect. Other sequences (like colors for example) work fine, the hyperlink one (which according to the source might be a gnome-terminal-only thing) doesn't. (screen is running inside gnome-terminal) How can I get screen to acknowledge my link sequence and display it properly?
You can pass through some text to the terminal screen itself runs in by putting it inside an ESC P, ESC \ pair (\033P%s\033\\ in printf format). So you should bracket inside \eP..\e\\ pairs all the parts of the sequence, except for the text which will appear on the screen ("This is a link"): printf '\eP\e]8;;https://example.com\a\e\\This is a link\eP\e]8;;\a\e\\\n' printf '\eP\e]8;;%s\a\e\\%s\eP\e]8;;\a\e\\\n' https://example.com 'This is a link' Or, from C: puts("\eP\e]8;;https://example.com\a\e\\This is a link\eP\e]8;;\a\e\\"); printf("\eP\e]8;;%s\a\e\\%s\eP\e]8;;\a\e\\\n", url, title); Putting the replacement text too inside \eP..\e\\ may result in screen losing track of the cursor position. This is documented in the GNU screen manual: ESC P (A) Device Control String Outputs a string directly to the host terminal without interpretation The "string" should should be terminated with a ST ("string terminator") escape, ie. \e\\ -- thence \eP..\e\\.
Using terminal escape-sequences within GNU screen
1,362,151,169,000
This is how the output of screen -ls looks like for many years on one older Debian machine: artax:~> screen -ls There are screens on: 46785.pts-6.artax (08/26/2019 04:41:05 AM) (Detached) 2499.pts-0.artax (05/11/2019 07:30:55 PM) (Detached) artax:~> screen --version Screen version 4.01.00devel (GNU) 2-May-06 But now, on the new CentOS, the output doesn't contain the date & time: user@comp:~$ screen -ls There is a screen on: 1759.pts-0.user-comp (Detached) 1 Socket in /var/run/screen/S-user. user@comp:~$ screen --version Screen version 4.01.00devel (GNU) 2-May-06 The date & time of the session is important for me - I have a nice script which uses this information. How do I invoke it in the CentOS version of the screen command? I searched the manpage but with no success. EDIT: there is also a difference on manual pages: Debian version: -ls [match] -list [match] does not start screen, but prints a list of pid.tty.host strings and creation timestamps identifying your screen sessions. CentOS version: -ls [match] -list [match] does not start screen, but prints a list of pid.tty.host strings identifying your screen sessions.
version 4.0.1 is very old :) the creation timestamp is a debian specific patch source : https://salsa.debian.org/debian/screen/blob/ab7d6dee8d34b09b192ae438a1639e53bcee2e29/debian/patches/80EXP_session_creation_time.patch because the number is the pid of screen , you can use ps to display the starting time of one process . ps -o lstart= -p 21628 Fri Nov 22 18:49:50 2019
screen -ls no longer displays session start date/time?
1,362,151,169,000
I run Biglybt as a daemon inside a screen session using the following command screen -c /home/pi/.screenconf -L -dmS Biglybt_screen /usr/bin/java -cp "/usr/share/java/jna.jar:/home/pi/biglybt_stock/BiglyBT.jar:/home/pi/biglybt_stock/dorkbox-systemtray.jar:/home/pi/biglybt_stock/commons-cli.jar:/home/pi/biglybt_stock/log4j.jar:/home/pi/biglybt_stock/junit.jar:/home/pi/biglybt_stock/swt.jar" -Djava.library.path=/home/pi/biglybt_stock -Dbiglybt.install.path=/home/pi/biglybt_stock -Dazureus.script=/home/pi/biglybt_stock/biglybt -Djava.net.preferIPv4Stack=true -Ddebug.swtexec=1 -Dazureus.config.path=~/.biglybt_stock com.biglybt.ui.Main --ui=console And I can stop the daemon by sending quit command to the screen session as below screen -S Biglybt_screen -p 0 -X stuff "quit ^M" now I want to make a service file so that when the system shutdown the screen session gets a quit command to be exited gracefully I tried this service file [Unit] Description=BiglyBt daemon After=network-online.target [Service] Type=oneshot User=pi RemainAfterExit=yes ExecStart=/usr/bin/screen -c /home/pi/.screenconf -L -dmS Biglybt_screen /usr/bin/java -cp "/usr/share/java/jna.jar:/home/pi/biglybt_stock/BiglyBT.jar:/home/pi/biglybt_stock/dorkbox-systemtray.jar:/home/pi/biglybt_stock/commons-cli.jar:/home/pi/biglybt_stock/log4j.jar:/home/pi/biglybt_stock/junit.jar:/home/pi/biglybt_stock/swt.jar" -Djava.library.path=/home/pi/biglybt_stock -Dbiglybt.install.path=/home/pi/biglybt_stock -Dazureus.script=/home/pi/biglybt_stock/biglybt -Djava.net.preferIPv4Stack=true -Ddebug.swtexec=1 -Dazureus.config.path=~/.biglybt_stock com.biglybt.ui.Main --ui=console ExecStop=/usr/bin/screen -S Biglybt_screen -p 0 -X stuff "quit ^M" [Install] WantedBy=multi-user.target but when I stop the service, the process just gets killed instead of ending the screen session, So what am I missing? UPDATE: This service file works [Unit] Description=BiglyBt daemon After=network-online.target [Service] Environment=DISPLAY=0.0 Type=simple User=pi Group=pi ExecStart=/usr/bin/java -cp "/home/pi/biglybt_stock/BiglyBT.jar:/home/pi/biglybt_stock/swt.jar" -Djava.library.path=/home/pi/biglybt_stock -Dbiglybt.install.path=/home/pi/biglybt_stock -Dazureus.script=/home/pi/biglybt_stock/biglybt -Dazureus.config.path=/home/pi/.biglybt_stock -Dazureus.overridelog=1 -Dazureus.overridelogdir=/home/pi/biglybtlogs/ -Ddebug.swtexec=1 com.biglybt.ui.Main --ui="console,telnet" ExecStop=/usr/bin/java -cp /home/pi/biglybt_stock/BiglyBT.jar -Djava.library.path=/home/pi/biglybt_stock -Dbiglybt.install.path=/home/pi/biglybt_stock -Dazureus.script=/home/pi/biglybt_stock/biglybt -Dazureus.config.path=/home/pi/.biglybt_stock com.biglybt.ui.Main --shutdown SuccessExitStatus=143 [Install] WantedBy=multi-user.target The problem now is that i can no longer start the swt ui(gui) of biglybt. The swt ui can be started either by telneting to the server and issue ui swt or running /usr/bin/java -cp "/home/pi/biglybt_stock/BiglyBT.jar:/home/pi/biglybt_stock/swt.jar" -Djava.library.path=/home/pi/biglybt_stock -Dbiglybt.install.path=/home/pi/biglybt_stock -Dazureus.script=/home/pi/biglybt_stock/biglybt -Dazureus.config.path=/home/pi/.biglybt_stock -Dazureus.overridelog=1 -Dazureus.overridelogdir=/home/pi/biglybtlogs/ -Ddebug.swtexec=1 com.biglybt.ui.Main --ui="swt" --open which will send request to the main process to start the swt ui. Unfortunately this runs fine inside regular terminal window but when running the main process inside systemd then this give Unable to init server: Could not connect: Connection refused inside the journal logs
Thanks to @ErikF and support from biglybt github account I was able to solve the issue, this service file now works for me [Unit] Description=BiglyBt daemon After=network-online.target [Service] Environment="DISPLAY=:0.0" Type=simple User=pi Group=pi ExecStart=/usr/bin/java -cp "/usr/share/java/jna.jar:/home/pi/biglybt/BiglyBT.jar:/home/pi/biglybt/dorkbox-systemtray.jar:/home/pi/biglybt/commons-cli.jar:/home/pi/biglybt/log4j.jar:/home/pi/biglybt/junit.jar:/home/pi/biglybt/swt.jar" -Djava.library.path=/home/pi/biglybt -Dbiglybt.install.path=/home/pi/biglybt -Dazureus.script=/home/pi/biglybt/biglybt -Dazureus.script.version=9 -Dazureus.overridelog=1 -Dazureus.overridelogdir=/home/pi/biglybtlogs/ -Duser.dir=/home/pi/biglybt com.biglybt.ui.Main --ui="console,telnet" ExecStop=/usr/bin/java -cp "/home/pi/biglybt/BiglyBT.jar" com.biglybt.ui.Main --shutdown SuccessExitStatus=143 [Install] WantedBy=multi-user.target Also I created a script to launch the swt(gui interface): #!/bin/bash /usr/bin/java -cp "/home/pi/biglybt/BiglyBT.jar" com.biglybt.ui.Main --ui=swt --open
Stop systemd service by sending command to screen session
1,362,151,169,000
I've just started using screen for the first time, and I somehow got it into a state where it wasn't recognizing any commands any longer. Ctrl-A n, Ctrl-A p etc wouldn't work. Meanwhile my cursor was also frozen in emacs, which never happens to me. So I opened another terminal, hoping that I could just reattach to screen and things would be better. But it won't let me connect, and it won't let me detach it either. I found an alternative command to try, but after the last command everything just hung again. -bash-4.1$ screen -r There is a screen on: 4511.pts-1304.unixscrna01 (Attached) There is no screen to be resumed. -bash-4.1$ screen -list There is a screen on: 4511.pts-1304.unixscrna01 (Attached) 1 Socket in /var/run/screen/S-sme. -bash-4.1$ screen -D [4511.pts-1304.unixscrna01 power detached.] -bash-4.1$ screen -r There is a screen on: 4511.pts-1304.unixscrna01 (Attached) There is no screen to be resumed. -bash-4.1$ screen -d -r 4511 My terminal hung completely at the last point. Any idea what could have happened here??
You're probably now connected to the old session, but the session may be in a wonky state for some reason. Try pressing Control-Q first: if XON-XOFF handshaking is enabled in the pseudo-terminal you've using to connect to the screen session, it might allow the session to resume. (Control-S is the XOFF control character, which means "pause transmission": if XON/XOFF handshaking is enabled in the pseudo-terminal, it will do just that. Control-Q is the XON character which means "resume transmission".) Then press Control-L: most full-screen terminal applications will understand that as a request to completely refresh the terminal display, in case it got corrupted for any reason. The bash shell will also clear the screen and display a fresh prompt. If you were using screen for a ssh session onward to another system, a network problem may have broken the SSH connection, in which case the ssh client will -by default- wait a very long time until it decides the other end must have disconnected. A tilde-dot (~.) key sequence can be used to terminate a hanging SSH session.
screen is dead and can't reattach?
1,362,151,169,000
I use iTerm2 on Mac and have customized control + ← and control + → to send hex 0x01 and 0x05 when pressed - which makes the cursor jump to the start and end of the line when typing or editing commands (opposed to one word at a time) - and the alt key plus an arrow makes the cursor move one word at a time. This works fine on remote linux systems when using SSH, until I start a screen session. The control + → still works fine, but when I try to use control + ← I just get a message in the screen status area: No other window. I found documentation that suggested adding these lines to /etc/screenrc or ~/.screenrc would bind the keys to next and previous windows: bindkey "^[[5D" prev bindkey "^[[5C" next And I thought the syntax for unbinding was to use this line with no command: bindkey "^[[5D" bindkey "^[[5C" I've also tried it with as follows: bindkey "^[[01" bindkey "^[[05" None of these things seem to work. /etc/screenrc is completely unchanged for Ubuntu 16.04 and there is no ~/.screenrc file at the moment ( i.e. nothing non-standard interfering ) How can I unbind this or debug it further to figure out where the hangup is?
The code 0x01 is Control-A which is the default command character in screen, so when you do control + ← twice you have the default action binding of other, i.e. other window, hence the message. You can change to a different command character, eg Control-b when you start screen: screen -e^Bb or you can put in your ~/.screenrc the line escape ^Bb
How can I disable keybindings / keybind in GNU screen?
1,362,151,169,000
I tried every solution from How to run Dropbox daemon in background? and nothing solves my problem: Basically, I already installed dropbox on my Ubuntu 12.04LTS headless server. I got init.d setup but the problem is that right now I cannot restart the server (other users are using it actively). So I am trying to start dropbox via SSH which works and dropbox starts to sync, but as soon as I disconnect from SSH dropbox stops runnning. I tried running it on a detached screen, using ($HOME/.dropbox-dist/dropboxd &)& and they all stop when I log out from SSH. I tried doing service start but it seems not to work and I don't know why..? $ sudo service dropbox start [sudo] password: Starting dropbox... $ dropbox status Dropbox isn't running! I followed the instructions: sudo chmod +x /etc/init.d/dropbox sudo update-rc.d dropbox defaults from http://www.dropboxwiki.com/tips-and-tricks/install-dropbox-in-an-entirely-text-based-linux-environment#debianubuntu and I got no error messages. Please help. I don't care as much about starting the process at server restart, as long as I can launch dropbox via ssh and keep it runnning after i log out. Thank you UPDATE & ANSWER: thanks a lot for all your answers. Thanks to user Nixgrrrl's comment, I realize that it was because I was using ssh -X (the default on my system). As soon as I did normal ssh, trying the humble dropbox start & worked :)
thanks a lot for all your answers. Thanks to user Nixgrrrl's comment, I realize that it was because I was using ssh -X (the default on my system). As soon as I did normal ssh, trying the humble dropbox start & worked :)
dropbox process stops when I log out of ssh
1,362,151,169,000
I want to be able to SSH to a remote host and restore a screen session with one command. Both hosts use UTF-8 locale. My problem is that then, inside the screen session, characters are encoded twice. As stated in other related questions, I need to pass the -t option to ssh command in order to allocate a pseudo-tty for an interactive session: Automatically (or more easily) reconnect to a screen session after network interruption Thus the command I use is ssh -t remotehost screen -dr. When I restore screen this way, the characters I send from the keyboard are encoded twice, and the characters I receive from the remote host are decoded twice: localhost % ssh -t remotehost screen -dr remotehost % echo ä | hexdump -C 0000000 c3 83 c2 a4 0a 0000005 This doesn't happen if I first connect to the remote host and then restore screen: localhost % ssh remotehost remotehost % screen -dr remotehost % echo ä | hexdump -C 0000000 c3 a4 0a 0000003 What I mean by "characters are encoded twice" is that normally I see the same output if I type: localhost % echo ä | iconv -f ISO-8859-1 -t UTF-8 | hexdump -C 00000000 c3 83 c2 a4 0a 00000005 The pseudo-tty allocation alone doesn't cause the problem. I've tried: localhost % ssh -t remotehost /bin/zsh remotehost % screen -dr remotehost % echo ä | hexdump -C 0000000 c3 a4 0a 0000003
That suggests the screen that you're attaching your session to thinks your terminal is not in UTF-8. It thinks for instance (if it assumes the charset is iso-8859-1 instead) that 0xc3 coming from the terminal device means a Ã. The screen session, however is running in UTF-8 (screen is a terminal emulator that can be attached to different types of terminals). So, when typing ä, you're sending 0xc3 0xa4. screen understands that you're typing two characters (à and ¤). It needs to convert them to their UTF-8 equivalent. On display, those UTF-8 characters are converted to their iso-8859-1 equivalent which is why you're seeing ä and not ä. You need to tell screen that your terminal is UTF-8. Usually, it's enough to set the locale to a UTF-8 one. Most ssh deployments pass the locale information from the client to the remote command. If your locale on the client is a UTF-8 one, then either ssh doesn't pass the locale environment variables, or sshd doesn't accept them, or the locale on the client side is not one of the supported ones on the server, or your ~/.bashrc on the server somehow overrides it. In any case, doing: ssh -t remotehost LANG=fi_FI.UTF-8 screen -dr (making sure fi_FI.UTF-8 is indeed a locale supported on the remote host, see locale -a to check) should fix it.
Characters are encoded twice when I ask SSH to reattach a screen session on the remote host
1,362,151,169,000
Suppose that I am running screen on a remote server with four open screens. Is there a quick way to cd all the screens to the working directory of the currently-open screen?
Here is a work-around: on one tab, record the CWD into a temp file, on the other tabs, cd to the just-saved dir. I would put these two aliases to my .bashrc or .bash_profile: alias ds='pwd > /tmp/cwd' alias dr='cd "$(</tmp/cwd)"' the ds (dir save) command marks the CWD, and the dr (dir recall) command cd to it. You can do something similar for C-shell.
`cd` all screens to the PWD of the current screen
1,362,151,169,000
How do I disable the output when you are done with a screen from the screen command? Example: function foo() { echo "Testing..." sleep 2 echo "Done!" } export -f foo screen -q bash -c "foo" &> /dev/null It all works as expected, however I cannot find out how to disable the "[screen is terminating]".
There are only two solutions that I can think of. The first is to modify the screen code itself and recompile. The second is to have something like an expect wrapper around the program (untested): #!/usr/bin/expect -f spawn screen -q bash -c foo interact { "\[screen is terminating]" exit }
Disable screen outputting "[screen is terminating]"
1,362,151,169,000
In bash, when I type screen -x and press tab twice, I get a list of all the running sessions. In zsh, when I type screen -ls and press tab twice, I get a list of all the running sessions and can tab through them, eventually select one when pressing enter, but this then executes screen -ls session-name when pressing enter again. What I want in zsh is to get a behavior for -x similar to -ls, so that I don't have to type the session name or select the session and go back and change ls to x. I can't find the code which implements the screen -ln tab-behavior in order to also implement it for -x, I've been searching/grepping through the list of .oh-my-zsh plugins but am getting nowhere. Any help is appreciated, or maybe some workflow tips. I use screen a lot and most of it is via screen -x.
The code is in _screen (completion is provided natively by zsh, it's not an additional plugin). Zsh completes all sessions for -ls but only attached sessions for -x. -x is intended to “Attach to a not detached screen session” (per the manual). But it also works if the session is detached. So both behaviors make sense. Ideally, this should be a configuration option for zsh's completion. To get the behavior you want instead of the current behavior, you need to change the line '-x[attach to a not detached screen (multi display mode)]: :->attached-sessions' \ to '-x[attach to a not detached screen (multi display mode)]: :->any-sessions' \ Here's some code you can put in your init file to monkey-patch the completion function to get the behavior you want. It needs to go after compinit (so after the oh-my-zsh lines if you use oh-my-zsh). # Monkey-patch the screen completion function to complete all sessions # after -x, not just detached sessions. autoload +X _screen # load immediately set -o extendedglob # needed for (#b) and # below and generally a good # thing to have in interactive shells functions[_screen]=${functions[_screen]/(#b)(\'-x[^:]#:[^:]#:->)attached-sessions(\')/${match[1]}any-sessions${match[2]}}
zsh gnu-screen tab completion for `-x` flag similar to `-ls`
1,362,151,169,000
I am trying to create a Docker container with screen session running some script. Dockerfile contains CMD screen -S session1 ./testLinux When I run it in detached mode it closes immediately, saying Must be connected to a terminal. How do I run persistent screen session inside detached docker container?
I can reproduce this with this Dockerfile: FROM centos:latest RUN yum -y install screen && rm -rf /var/cache/yum CMD screen -S session1 sleep 99999 when I run it with docker run <imageID> I get Must be connected to a terminal. Screen needs a terminal (tty) to function. The solution is to add -tid to the run flags, from the help: -d, --detach Run container in background and print container ID -i, --interactive Keep STDIN open even if not attached -t, --tty Allocate a pseudo-TTY See https://docs.docker.com/engine/reference/run/ for reference.
Persistent screen session inside Docker container
1,362,151,169,000
From https://unix.stackexchange.com/a/485290/674 Further down in the netstat output is UNIX sockets: Active UNIX domain sockets (servers and established) Proto RefCnt Flags Type State I-Node PID/Program name Path <snip> unix 2 [ ACC ] STREAM LISTENING 21936 1/systemd /run/dbus/system_bus_socket <snip> unix 3 [ ] STREAM CONNECTED 28918 648/dbus-daemon /run/dbus/system_bus_socket We can see that both of these processes are using the UNIX socket at /run/dbus/system_bus_socket. So if you knew one of the processes, looking at this, you should be able to determine the other end. Does that mean any pair of server and client processes based on Unix domain socket should appear in the output of netstat like the one above? In other words, should netstat always show both server and client processes? GNU Screen also runs as server and client processes based on Unix domain socket, so should they appear in the output of netstat? Why does netstat in fact not show Screen client but only Screen server process like the one below, $ sudo netstat -ap | grep -i screen unix 2 [ ACC ] STREAM LISTENING 4533106 27525/SCREEN /run/screen/S-t/27525.test while ps shows both? $ ps aux | grep -i screen t 19686 0.0 0.0 45096 3292 pts/7 S+ 22:19 0:00 screen -r test t 27525 0.0 0.0 45780 3292 ? Ss 07:22 0:00 SCREEN -S test Thanks.
screen processes don’t maintain socket connections while they’re running; they open and close socket connections as needed when they have messages to send. Thus, when you run screen -r to reconnect to an existing session, it connects to the existing process using a socket, negotiates various settings, and when it’s good to go, attaches to the appropriate terminal, and closes the socket. That means that when you run netstat, unless you happen to do so exactly when two screen processes are communicating (which doesn’t happen all that often), you won’t see an open socket connecting two screen processes.
Why doesn't `netstat` show Screen client but only Screen server process?
1,362,151,169,000
I am trying to write the time in a screen in shell script, however, I am extremely inexperienced with the screen command. Thus, apologies for my mistakes. I have a transmitter that operates in a screen created by the shell script I wrote, as follows: screen -S trans -L /dev/ttyACM0 screen -S trans -X stuff 's'$(echo -ne '\015') sleep 8s screen -S trans -X quit I am not quite sure what the second line is echoing. Nevertheless, this code produces a screenlog.0 file at the end of the process, and my goal is to write the time ($(date)) at the end of this file. Thank you.
Sounds simple enough, let me know if I missed something. At the end of that script, last line put: date >> screenlog.0 entire script: screen -S trans -L /dev/ttyACM0 screen -S trans -X stuff 's'$(echo -ne '\015') sleep 8s screen -S trans -X quit date >> screenlog.0
Writing to a screen in Shell Script
1,362,151,169,000
I have created multiple screen to run the same piece of code with different parameters. The way I'm doing it right now is manually attaching one screen, pass the command and arguments and then Ctrl a+d to detach that screen. Then again attaching a different screen and again passing the arguments and detaching from that screen. Is it possible to write a bash script to do this whole process automatically?
Creating multiple screen sessions is probably not the best option. Screen supports the notion of putting multiple windows within one session, which makes collections like that easier to handle. There's ^A 1, ^A 2 etc. ^A ' and ^A " to switch between the windows and ^A w to list them. Going with one screen session, you can start a session and then the commands inside with something like: #!/bin/sh screen -d -m -S test screen -S test -X screen -t title somecommand someargs... screen -S test -X screen -t othertitle somecommand otherargs screen -d -m starts a new detached session, -S gives the session a name or refers to one by name. -X sends the rest of the command line as a command to a running session, and the screen command (within screen) opens a new window and runs a command there. -t can be used with screen to give the window a title. Or, you could put the commands for screen in a file and then use :source to run the file (similar to .screenrc). See the manual for some examples and a reference on the commands screen supports. (There are a truckload.)
Accessing back and forth screens through bash script
1,362,151,169,000
I am using screen within a deployment script to launch several processes detached. For example : /usr/bin/screen -dmSL ${USER}_selenuim java -jar selenium-server-standalone.jar -role hub -servlets com.example.local The problem I see is that this service will be on for an extended duration and the output is quite verbose as per a requirement however, the log file which is created (screenlog.0) is growing an an extremely large amount. Is it possible to split this log file or create another log file after it reaches a certain size WITHOUT stopping and restarting the screen services. Or some other combination to reduce the file sizes of logs. I have referred to the screen Manual however I could not find an answer..
My version of screen opens the log file in append mode, so any writes are always at the end of the current size of the file. This means you can independently reduce the size of the file, for example to 0, and the logs will continue from there. You can use the command truncate --size 0 screenlog.0 to shrink the file back to size 0. You could copy the contents of the file first if you want to preserve them. Sadly there would be an small interval between the copy and the truncate when new data might be added and would be lost. You could issue the signals SIGSTOP and SIGCONT on your process or the screen process to temporarily pause them whilst you do the copy and truncate.
Multiple log files with screen
1,362,151,169,000
I am currently running mathematica on a Linux cluster, I want the job running stably even if I log out. So I use nohup. However, I found sometimes nohup terminates without any sign (I can't see any error message in the output file, it just stopped in the middle of a calculation.) It maybe due to Mathematica. But I think maybe I should try screen. So I came up with this question. What is the difference between nohup and nohup in a screen? Will nohup inside a screen more stable than merely nohup?
It will not make a real difference, in the sense that if you run screen (or tmux) and you disconnnect there will be NOHUP signal sent to your application whether you start it with nohup or not. I suggest you try it out by using screen/tmux and just start the program without nohup. Then forecfully disconnect, login and again and reattach to the previous session. You'll see that your session just keeps on working and that you can see its output (scrolling back in the buffer requires some special commands) and that you can (probably) interrupt the running program by pressing Ctrl+C, essentially as if you never disconnected. So where your original program somehow terminates unexpectedly and hopefully writes to nohup.out what is the cause, now that output goes to the screen session buffer. But if it doesn't output anything when using nohup you will not get more information when running inside screen. It is not nohup that terminates, it is your program that does, despite running "under" nohup.
Is there a difference between nohup and nohup in a screen?
1,362,151,169,000
I have started a few processes in the past initiated via the screen command. Most of those scripts have already finished running, but looks like the screens are still sitting there idle. I can see them when I do a ps aux | less to see all processes. How can I see all the screens and whether there is an active script running in them. Thanks
To see the current list of running screens: screen -list The first part of the screen's name is its PID. To see the tree of currently running processes spawned from that parent process, run: pstree <PID> or, for a more detailed output, pstree -a <PID> | less To reattach to a screen (and detach it if it's already attached elsewhere), run: screen -rd <PID> To kill a screen once you've established you no longer need it, you have a couple options. If you're currently attached to the screen, you can simply use Ctrl + a, k, which will kill the screen and all its windows. Alternatively, if you're not attached to the session, you can use: kill <PID> screen -wipe <PID> to kill it and remove it from the list of screens.
Find all idle screens
1,362,151,169,000
I am using the RemoteLoginAutoScreen script to start a screen session when I ssh into a host. Differences from linked script: I am using zsh and the RemoteLoginAutoScreen uses bash The problem that I'm running into is that my ssh connect was disconnected (which happens frequently and hence the auto-screen configuration) and I'm having trouble reconnecting to my existing screen session. On the host I can see that my screen process is still running and the screen sockets still exist: $ ps auxww | grep -i screen | grep alexq alexq 1818 0.0 0.0 103452 868 pts/19 S+ 18:08 0:00 grep --color=auto -i screen alexq 20270 0.0 0.0 120040 2004 ? Ss Jul21 0:19 SCREEN -R $ ls -al /var/run/screen/S-alexq total 6 drwx------ 2 alexq alexq 4096 Jul 29 17:26 . drwxrwxr-x 5 root screen 4096 Jul 21 21:33 .. prwx------ 1 alexq alexq 0 Jul 29 17:46 20270.pts-14.myhost But when I'm logged in (without being in a screen session) screen can't find my existing session: $ screen -ls No Sockets found in /tmp/uscreens/S-alexq. Based on this question I've tried setting the SCREENDIR environment variable to /var/run/screen/S-alexq But when I do that screen still can't find the sessions: $ export SCREENDIR=/var/run/screen/S-alexq $ screen -ls No Sockets found in /var/run/screen/S-alexq. $ export SCREENDIR=/var/run/screen $ screen -ls You are not the owner of /var/run/screen. What I'm really confused about is that when I replace starting screen with "screen -ls" in my ~/.zshrc file I get the following printed to the console: There are screens on: 20270.pts-14.myhost (Attached) 1 Sockets in /var/run/screen/S-alexq. So for some reason screen during my ssh login can find the existing session but when I'm on the console screen can't find the session. Can anyone help me to figure out why screen can only see the sessions during my ssh login and not afterwards?
You have two copies of screen. One of them stores its sessions in /tmp/uscreens and the other stores its sessions in /var/run/screen, so they don't see each other's sessions. Even if you could force them to see each other's sessions there's a chance that the copies of screen are different versions and bad things would happen if the two talked to one another. However in any case you've already observed that it doesn't allow you to force it to use a different session directory using $SCREENDIR and that's a security measure (because screen is privileged, probably setuid or setgid, depends on the exact OS and configuration). The problem happens because you have a different $PATH depending on how exactly you log in. The solution is to use the same copy of screen to resume a session as was used to start it. Or you can disable or uninstall one of the copies of screen to remove the possibility of future confusion.
running screen in a shell can't find sessions but running screen during ssh login can
1,362,151,169,000
Is there a way to take a "screenshot" of linux screen command. In other words can "screen -r" command to be called with the same behaviour as "top -b -n 1" - print contents once and exit. Background - I have a screen process that's running on my server. I want to be able to show it's contents in web for example. Or take a snapshot and pass it to a script once in a while. Maybe if there is a way to capture current console screen it'll work in screen.
You can get a 'hardcopy' of a screen session with the screen command 'hardcopy' An automated way to do this would be something like: rm ~/hardcopy.0 screen -X -p0 hardcopy tail -30 ~/hardcopy.0 It was also pointed out 'screen -X -p0 hardcopy -h /tmp/out.txt' might be more useful. That version will copy the entire scrollback buffer into /tmp/out.txt instead of some ~/hardcopy.<number>
Screenshot of a window in a detached or remote screen
1,362,151,169,000
Our school HPC does not have a scheduler. So there is nothing like job queue. Hence, I cannot automate parallel job submission by qsub or sbatch. What I have been using to "submit" a job is by using screen: type screen, then press Enter, then type ./runMyJob.sh, then press CTRL+a followed by d to detach. Now I wish to automate/script the process of starting several parallel screen sessions, then running a job in each session, and finally detaching all the screen sessions. As you can see, during the manual operations, I pressed Enter and CTRL+a followed by d. How do I script these key-pressing operations? P.S.: any suggestion that helps achieve parallel job submission in a HPC without a scheduler is very much welcomed!
Don't think of it in terms of pressing keys, think of it in terms of accomplishing a task. Pressing keys is a way to do things interactively. The way to accomplish things automatically is to script them. To start a job in screen and detach it immediately, run screen -md ./runMyJob.sh If you want to make your jobs easier to find, you can pass the option -S to set a session name. For example, you can write the following script, which uses the name of the job executable as the session name: #!/bin/sh screen -md -S "${1##*/}" "$@" Call it something like submit, put it in a directory on your PATH (Single-user binary installation location? and How to add home directory path to be discovered by Unix which command? may help), make it executable (chmod +x ~/bin/submit). To start a job, run submit ./runMyJob.sh For parallel execution, you may want to investigate GNU parallel. Note that a job submission framework does more that start jobs. It also arranges for them to run where there is available CPU time and memory, and to send logs to the submitters. You should request that your administrators set up a proper job submission framework.
Automate starting several parallel screen threads?
1,362,151,169,000
I run a simple minecraft server. I made a script awhile ago for Ubuntu that would automatically create a Gnu screen and start said server. I decided get a new server with Debian instead. Now for some reason, the script will not work and I have no idea why! sleep 5 screen -dmS mc sleep 1 screen -p 0 -S mc -X stuff "cd /home/server/Desktop/ServerSoftware/Minecraft/modpacks^AgrarianSkiesHQ^3_1_1^AgrarianSkiesHQServer" sleep 1 screen -p 0 -S mc -X eval "stuff \015" sleep 1 screen -p 0 -S mc -X stuff ./ServerStart.sh sleep 1 screen -p 0 -S mc -X eval "stuff \015" How it's supposed to work: Start a minimized GNU-Screen Change Directory to the minecraft server directory Start the server Basically how it doesn't work is that it WILL create the screen and be detached from it. But after that, when I resume the screen I have to CTRL+c to be able to input anything. the "cd" command never gets sent through, nor the ./StartServer.sh The "^" in the CD line are supposed to be there. I have tested the command in terminal and it works as wanted.
Your script doesn't work because ^ introduces a control character sequence. The two-character ^A stuffs a Ctrl+A character, which bash interprets as the command to go to the beginning of the line. You need to use \^ instead. screen -p 0 -S mc -X stuff 'cd /home/server/Desktop/ServerSoftware/Minecraft/modpacks\^AgrarianSkiesHQ\^3_1_1\^AgrarianSkiesHQServer^M' screen -p 0 -S mc -X stuff './ServerStart.sh^M' I can't find any record in the Screen changelog showing that this behavior changed, but if your script worked on an older machine, it must have.
Why does this script work on Ubuntu, and not Debian?
1,362,151,169,000
Whenever I try to run screen under a Zsh shell that I compiled under my home directory, I get the following error: > screen Cannot exec '/my/path/to/zsh/bin/zsh' The Z shell is perfectly functional, and I have verified that I can run screen if I invoke it using a system shell (e.g. csh). I usually get into zsh with: exec zsh. Here is some additional info about my system: > echo $SHELL /my/path/to/zsh/bin/zsh > echo $ZSH_VERSION 5.0.0 > which screen /usr/bin/screen > screen --version Screen version 4.00.03 (FAU) 23-Oct My .screenrc just has two lines in it: escape ^A^A bind o other In case it matters: /my/path/to/zsh/ refers figuratively to a path under my home directory. Update Output of calling file: > file /my/path/to/zsh/bin/zsh > /~/sw/zsh/bin/zsh: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for > GNU/Linux 2.6.9, dynamically linked (uses shared libs), > for GNU/Linux 2.6.9, stripped But I can successfully run /my/path/to/zsh/bin/zsh and enter zsh from my csh shell. I usually switch to zsh with exec /my/path/to/zsh/bin/zsh Below are the ls details on /my/path/to/zsh/bin/zsh -rwxr-xr-x 2 YYYY ZZZZ 651K Jan 3 11:58 zsh* Mi .login is empty (it only has comments on it) I don't have a .profile file cat/etc/*-release: Scientific Linux SL release 5.1 (Boron) Any thoughts on what may be causing this and how to get screen to work with my local installation of zsh?
This is embarrassing: the value of of my $SHELL variable was not correct (it had a typo). I apologize - I will make sure I triple check these things before posting a question like this and wasting everyone's time. Thanks so much to all for your help.
Screen: "Cannot exec /my/path/to/zsh" with local shell
1,362,151,169,000
Possible Duplicate: sending text input to a detached screen With reference to the answered question: Sending input to a screen session from outside I am trying to write a script that will create a screen and then stuff input (in my case, UNIX commands) into the shell that I want it to execute. Here's what I have till now: $ screen -dmS new_screen bash $ screen -S new_screen -X stuff "cd /some/path/ some_script_file.sh " <--This new line is required to execute the above command. $ # Note: See comments. We could insert the newline character instead of 'hard-coding' a newline string literal. For some reason, the screen gets created fine and enters the bash shell. But the cd and some_script_file.sh commands don't get stuffed to the screen's bash shell. Now the really strange part is.. After I detach from the screen, re-execute the stuff command as below.. $ screen -S new_screen -X stuff "cd /some/path/ some_script_file.sh " and then attach back into new_screen. Now I see that the commands were correctly stuffed and executed in the bash shell inside screen. Not sure where I am going wrong here, there seems to be any issue stuff-ing commands into a not as yet attached screen.
When a screen session is first created, no window is selected. As such, when you send your commands, screen doesn't know which window to send it to. Once you have attached to the screen, however, the window has become selected, which is why you can send commands after doing so. To select a window from the command line you need to use the -p option. Here's a modification of your command that should work: screen -S new_screen -p 0 -X stuff "cd /some/path/ some_script_file.sh "
Unable to 'stuff' commands into a created 'screen' immediately after creating it [duplicate]
1,362,151,169,000
I just set up a systemd.service in order to run cmus (a console-music-player) detached to a screen at startup. i don't get sound, when starting via remote with no user logged in to the machine. i do get sound, while i'm logged in as the user i set the service to run. but: i can't change volume via remote, it says "mixer is not open". when i just start cmus detached to a screen logged in as the user manually, i can log out again, and do have sound and mixer via remote. when i set the service to run as root (which i don't want, for several reasons) it does have sound and mixer. unfortunately Environment=XDG_RUNTIME_DIR=/run/user/1000 as suggested here doesn't help (1000 is the right one). so the question is: what is missing here to get alsa fully working in my systemd-service as a user? my current unit looks like this: [Unit] Description=cmusd (consolemusicplayer in screen with remote-web-server) After=syslog.target network.target sound.target [Service] Type=forking User=myusername WorkingDirectory=/home/myusername/cmus_daemon ExecStart=/home/myusername/cmus_daemon/cmusd.init start ExecStop=/home/myusername/cmus_daemon/cmusd.init stop Environment="HOME=/home/myusername" "USERNAME=myusername" [Install] WantedBy=multi-user.target Where cmusd.init start does basically screen -dmS cmusplayer cmus --listen $CMUS_IP my system is a ubuntu server 19.10 on a small board with optical audio.
allright, after more searching and experimenting i found a solution, that works like a charme at least on this ubuntu: just add Group=audio. No environment needed. [Unit] Description=cmusd (consolemusicplayer in screen with remote-web-server) After=syslog.target network.target sound.target [Service] Type=forking User=myusername Group=audio WorkingDirectory=/home/myusername/cmus_daemon ExecStart=/home/myusername/cmus_daemon/cmusd.init start ExecStop=/home/myusername/cmus_daemon/cmusd.init stop [Install] WantedBy=multi-user.target
no alsa-sound in systemd-service (using screen)
1,362,151,169,000
I am interested in having a single file open with vim in two shells at once. The use case I have in mind is two windows of gnu screen running on a tty. The catch is that I would like the instances of vim to be coordinated in the sense that edits in one window manifest instantly in each window. I would also like different cursor positions in each window, so something like just having two screen windows displaying the same shell is not what I am looking for. For example, I would like to be able to be in edit mode on line 1 in my first window, and also in edit mode on line 200 in my second window. I would like edits from one window to immediately manifest in the other window, and I would like a save action in one window to save all changes that have been made in each window. Is anything like this possible? If not with vim, with another editor?
You should really differentiate between opening the file twice or just displaying it's contents twice. Opened separately (in two shells / xterms) the coordination is via :e! etc. in vim, but it is not practical and not what you want. If you just :sp in vim, you get a instant duplication; but this is not "two shells". And now, if you "split" (or multiplex) your shell, you will get something in between. It is quite impossible to implement what you want, without a additional layer. That would be a database system.
Can you run vim (or another editor) in two shells at once on a single file, in a coordinated way?
1,362,151,169,000
I've been using screen (v4.03.01) for a while now and really like it. I've heavily customized my .screenrc, however for some odd reason the layout commands don't take on launch. If I source ~/.screenrc, they do take and my layout changes to what I want. Of note might be that I start screen with a crontab @reboot as the same user the .screenrc belongs to. Why does this happen and how do I fix this? Here's my .screenrc: startup_message off altscreen on bell_msg "Window % wants your attention!^G" vbell off sorendition "= KW" caption string "%{KW}" defscrollback 5000 # backtick 0: get cpu usage backtick 0 0 0 sh $HOME/.screenrc.cpu # backtick 1: get ram usage backtick 1 1 1 $HOME/.screenrc.ram hardstatus alwayslastline hardstatus string "%{= Kk}[ %{= KW}%H%{-} ] CPU: %{= KW}%0` %{-}RAM: %{= KW}%1` %{-}< %L=%-w%40L>%{= wk}%n %t%{-}%+w%-21= > [ %{= KW}%0c%{-} | %{= KW}%0d %M%{-} ]" # %{= Kk} : set colors to black on bright black # [ : literal # %{= KW} : set colors to bright white on bright black # %H : hostname # %{-} : reset colors to previous (black on bright black) # ] CPU: : literal # %{= KW} : set colors to bright white on bright black # %0` : execute backtick 0: cpu usage # %{-} : reset colors to previous (black on bright black) # RAM: : literal # %{= KW} : set colors to bright white on bright black # %1` : execute backtick 1: ram usage # %{-} : reset colors to previous (black on bright black) # < : literal # %L= : padding anchor: prevents truncation of previous # %-w : previous windows # %40L> : padding anchor: next element is at 40% of the space between previous and next anchors # %{= wk} : set colors to black on white # %n : window number # %t : window title # %{-} : reset colors to previous (black on bright black) # %+w : next windows # %-21= : padding anchor: next character is 21 characters from the right of the screen # > [ : literal # %{= KW} : set colors to bright white on bright black # %c : time (24h) # %{-} : reset colors to previous (black on bright black) # | : literal # %{= KW} : set colors to bright white on bright black # %d : day of month # %M : three-letter month # %{-} : reset colors to previous (black on bright black) # ] : literal # bind function keys (f1-f10) to window bindkey "^[OP" select 0 bindkey "^[OQ" select 1 bindkey "^[OR" select 2 bindkey "^[OS" select 3 bindkey "^[[15~" select 4 bindkey "^[[17~" select 5 bindkey "^[[18~" select 6 bindkey "^[[19~" select 7 bindkey "^[[20~" select 8 bindkey "^[[21~" select 9 bindkey "^[[1;5D" prev # ctrl-left to switch to previous window bindkey "^[[1;5C" next # ctrl-right to switch to next window bindkey "^[[1;5B" focus # ctrl-down to switch to next region bind = resize +1 #ctrl-= to embiggen region bind - resize -1 #ctrl-- to shrink region screen -t shell 0 bash screen -t shell 1 bash screen -t shell 2 bash screen -t shell 3 bash screen -t shell 4 bash screen -t shell 5 bash screen -t root 6 su - screen -t something1 7 bash screen -t something2 8 bash screen -t something3 9 bash #layout stuff layout new default layout autosave on split -v resize 60% split -h resize 15% select 7 focus down select 0 focus right split -h select 8 focus down select 9 focus left focus up layout save default layout attach default layout select default
You found a bug. And a nasty one at that. The layout family of commands appear to be dependent on a controlling terminal (a TTY or PTS must be present for the command to work). I can replicate the problem without going through crontab: I append the following to my .screenrc: layout new lay1 split -v layout new lay2 split -v layout attach lay2 Running screen directly gets me the layout: screen But performing the following fails to find the layouts: screen -dm && screen -r In the last command I can still list the layouts using :layout show, but goddamn, now it is when the bug becomes nasty. If I try to change the layout (with :layout next or :layout prev), screen falls into an infinite loop. Moreover, since the screen binary on my system is SUID root (I need multiuser support) the bug becomes worse. Once the user process has been killed the root process starts an infinite loop and eventually crashes. A possibility of crashing an SUID process, or even just capability of creating several root processes sucking CPU resources in infinite loops, is very dangerous. I have tested it on your version of screen (4.3.0) and also on 4.5.0 (the latest version) where the bug still exists. I'm in the process of compiling the source with -DDEBUG and reporting the bug to the development team of screen. The -DDEBUG screen fails with: ASSERT(l->l_cvlist != cv) failed file canvas.c line 294 Therefore it is likely that the infinite loop tries to find something in that linked list and fails over and over. Hacky workaround screen allows you to bind the eval method. Therefore you can add to your .screenrc something like: bind g eval 'layout new default' 'split -v' 'resize 60%' 'split -h' 'layout select default' The hacky part is that it must be on a single line, screen does not have any way of escaping long lines in .screenrc. Then you can get your layout with a single (well double) keystroke after you get into the screen (Ctrl+ag). g is normally bound to the system bell, so you should not miss it. But you can bind any key you like.
screen layout operations in .screenrc not working
1,362,151,169,000
I am inside a screen session, and from there want to launch another screen. However I don't want the new screen to be within the existing ( or a child process of the existing ). I.e. if I simply start screen from the existing screen I get a process tree like this: ├── screen 1 │ └── screen 2 but I want: ├── screen 1 ├── screen 2
From the manpage, the -m option is what you want -m causes screen to ignore the $STY environment variable. With "screen -m" creation of a new session is enforced, regardless whether screen is called from within another screen session or not. So $ screen -m should do what you want. This second screen instance can then be independently detached, re-attached, etc. If you want this second screen to start off detached then -d -m is a good option pair.
Launch top level screen from inside screen
1,362,151,169,000
Commonly I'm working with a single screen with many windowlist in it. ex: $ screen -r work [ctrl]+[A] , ["] Num Name Flags 0 root $ 1 bash $ 2 bash $ 3 alpha $ 4 alpha $ 5 samsung root $ 6 samsung $ 7 sshdj $ 8 light $ 9 dev01 $ 10 bash $ 11 ... *Problem** Host reboot forces me to bind windowlist again manually. Is there any workaround to bind windows list and window names for screen session automatically ?
If you want to recreate all the windows you can put in your ~/.screenrc lines with the name, number and command, eg: screen -t root 0 bash screen -t bash 1 bash screen -t alpha 3 bash or you can run from the command line the equivalent commands eg: $ screen -S work -X screen -t samsung 6 bash If you want to name or rename existing windows you can do so with eg: $ screen -S work -p 5 -X title 'samsung root'
screen list presettings
1,459,528,977,000
I was wondering if there was a program like GNU/screen or tmux that would allow me to attach or detach a session with a running process but would not provide all of the other features such as windows and panes. Ideally the program would be able to run in a dumb terminal (a terminal without clear). My use case is to use either the shell or the terminal that are built into emacs to run a program and have that program keep running even if emacs crashes. Tmux and screen are incompatible with shell because shell does not support clear. And although they work in the terminal the output is improperly formatted in part because of the bottom bar and also because of the quirks of term-mode. Thank you!
dtach is a wafer-thin terminal session manager, now forked on github, or doubtless easily installed via the ports or package system for your operating system. (Of historical interest may also be the dislocate example script distributed with expect.)
Is there a program like tmux or screen but only for attaching or detaching a session
1,459,528,977,000
Consider the following script: #!/bin/bash OFILE='log' echo 'ok' > ${OFILE} kill -SIGSTOP $$ echo 'after stop' > ${OFILE} In an interactive shell the script is stopped and the output is ok. However, if it is started as screen -d -m ./test.sh the output is after stop. Does screen handle the signal? How to suspend a process in a screen session?
Examination of the source code of GNU screen-4.0.2 showed that screen checks if its child processes are stopped and then tries to resume them with SIGCONT. Here is a relevant part of the screen.c: 1561 if (WIFSTOPPED(wstat)) 1562 { 1563 debug3("Window %d pid %d: WIFSTOPPED (sig %d)\n", p->w_number, p->w_pid, WSTOPSIG(wstat)); .... 1578 /* Try to restart process */ 1579 Msg(0, "Child has been stopped, restarting."); 1580 if (killpg(p->w_pid, SIGCONT)) 1581 kill(p->w_pid, SIGCONT); 1582 } It seems this behaviour cannot be changed with an option or via a config file. The suggested solution to stop screen process might have undesirable side effects. A better approach is to hide stopped process from the screen. For a bash script this can be done with a subshell: #!/bin/bash ( OFILE='log' echo 'ok' > ${OFILE} kill -SIGSTOP ${BASHPID} echo 'after stop' > ${OFILE} ) For other shells it might be not so straightforward, e.g. for tcsh: #!/bin/tcsh (\ set OFILE='log' ;\ echo 'ok' > ${OFILE} ;\ kill -STOP `exec sh -c 'echo ${PPID}'` ;\ echo 'after stop' > ${OFILE} \ ) The key difference is the method to get PID of the subshell, more info here. Alternatively, the script can be started without modification with a wrapper script: #!/bin/bash SCRIPTDIR="$(dirname "$(readlink -f -n "$0")")" ${SCRIPTDIR}/test.sh To run: screen -d -m ./wrapper.sh
Why doesn't SIGSTOP work inside screen session?
1,459,528,977,000
In my usual setup, I use use matlab-emacs to run Matlab through the Emacs GUI. I run Matlab and emacs on a Linux server, and use ssh and X forwarding so this all shows up on my local Ubuntu laptop. I would like to further complicate this setup by running emacs in screen. This mostly works with the notable exception that the keyboard shortcut Ctrl+Alt+Enter which tells Matlab to run a block of code, doesn't seem to do anything. I presume this shortcut is getting sent perhaps somewhere locally on my own machine? I notice the menu bar at the top of my terminal on my laptop changes when I try to run this command. Does anyone have a clever suggestion for how I can get Ctrl+Alt+Enter to run Matlab code blocks as expected?
Terminals transmit characters¹, not keys. When you press a key or key combination like Ctrl+Alt+Enter, the terminal has to translate it to a character or character sequence. There aren't nearly enough characters to represent all keys, so most such combinations are transmitted as escape sequences: a sequence of characters starting with the escape character. There's no universal standard for the escape sequences, though there are some common conventions. For example, Alt+key often sends the escape character followed by the character or escape sequence for key; but there's no standard for what Ctrl+Enter sends. Some terminals are configurable, some have hard-coded escape sequences. See also Problems with keybindings when using terminal for a more detailed explanation as well as possible solutions with Xterm. If you can't get Ctrl+Alt+Enter to be transmitted through your favorite terminal, you can choose a different key binding. Figure out what command Ctrl+Alt+Enter runs by pressing C-h c C-M-return when you're using Matlab in a GUI Emacs. Then type C-h w matlab-foo RET where matlab-foo is the command name; this will tell you what key(s) matlab-foo is bound to. If there isn't a binding that you can type conveniently, add one to your init file, with something like (defun my-eval-after-load-matlab () (define-key matlab-mode-map [f9] 'matlab-foo)) (eval-after-load "matlab" '(my-eval-after-load-matlab)) For "matlab", substitude the name of the Lisp file that defines the matlab-foo command. To find out what that is, type C-h k C-M-return; this tells you something like “C-M-return runs the command matlab-foo, which is an interactive compiled Lisp function in `matlab.el`”. The name of the Lisp file is that last bit on the line, minus the .el part. For matlab-mode-map, substitute the name of the keymap; this is generally the name of the major mode (C-h v major-mode RET, “Its value is matlab-mode”) plus -map at the end. Alternatively, do you really need to use Screen? If you're only using it so that Emacs survives the disconnection, this isn't actually necessary. Start Emacs as a daemon (emacs --daemon), and connect to it remotely over SSH by running emacsclient -c to open a new GUI frame. You can open and close GUI frames on multiple displays, and Emacs will keep running even if the displays come and go. ¹ Actually bytes, but that bit is irrelevant here.
I cannot use the keyboard shortcut <ctrl>+<alt>+<enter> in matlab running in emacs running in screen
1,459,528,977,000
Though I have the feeling the answer might be already out there, after reading several questions I did not manage to solve my problem. Apologies in advance in case of duplication. Current Situation: I have 1 screen detached I cannot manage to take control of: There is a screen on: 9667.pts-11.compute-2-1 (Detached) 1 Socket in /var/run/screen/S-pan. Whenever I do screen -r, -R, -d -r, -D -RR, the ssh session gets stuck and not responsive. Question: I am looking for a method to clear the screen list (I am not particularly interested in recovering that screen). Any help is highly appreciated.
If you just want to get rid of this screen session , you can do: kill 9667; screen -wipe
Linux screen: Clearing Screen List
1,459,528,977,000
I'm kind of new to bash scripting and I'm having trouble figuring out how to accomplish this. I'm working on a script that is designed to backup and manage a java application that runs within a screen session. The goal is to be able to have multiple instances of the java application running on the different machines and to be able to control them over ssh from the script. A feature I would like to have is the ability to easily call up the screen session of one of the java instances and display it to the user. So if the screen session is running on Machine A and I want to show it to the user on Machine B, I want to be able to initiate an ssh connection and call that up programmatically. In short, I want to mimic the following user commands in a bash script: ssh [email protected] screen -r ScreenName #Run from inside of ssh session
How about: ssh user@host -t screen -r
Bash Script Display Remote Screen Session to User
1,459,528,977,000
I have a script 'myscript.sh', that calls a vendor script 'vendorscript.sh'. The vendor script runs screen in the foreground. I would like to run the vendor script with screen detached. If possible I would like to do this without hacking the vendorscript.sh or vendor_screenrc. Is there a way to do this? myscript.sh: # some other commands ... source vendorscript.sh vendorscript.sh: # some other commands ... exec screen -c vendor_screenrc
If vendorscript.sh does not use an absolute path to launch the screen program, you could try manipulating the $PATH prior to execution. This also assumes that the $PATH is not reset/manipulated within vendorscript.sh. For example, I've created a directory /opt/vendor and created a shell script in it called screen: #!/bin/bash exec /usr/bin/screen -d -m "$@" And in myscript.sh: #!/bin/bash PATH="/opt/vendor:$PATH" source vendorscript.sh Because /opt/vendor is first in the $PATH, the vendorscript.sh will use my wrapper script instead of the screen binary. According to man 1 screen: -d -m Start screen in "detached" mode. This creates a new session but doesn't attach to it. This is useful for system startup scripts. And the "$@" passes through the remaining arguments from the original invocation.
script that calls a third party script that calls screen - how to start screen detached?
1,459,528,977,000
I've been trying to port my Windows .vimrc to Linux, to use on the command line (on gnome-terminal). Everything works fine, except for the colorscheme. It looks like it's loaded (:colorscheme returns solarized; :set t_Co returns t_Co=256 and :set background returns background=light), but it looks ugly on my terminal. If I run any of those commands again manually (either setting colorscheme, t_Co or background), then the theme displays normally. This is the .vimrc.bundle that's sourced on my .vimrc GVim also behaves normally. I tried other terminals (xterm, urxvt, screen), but none worked. Edit: Looks like there's some sort of conflict with a plugin loaded by Vundle. If I comment out the source ~/.vimrc.bundle, the colorscheme is loaded properly.
I'm hazarding a guess that given the number of plugins you have related to colors that one is interfering. I'd comment these out and see if that resolves the issue: " Bundle 'altercation/vim-colors-solarized' " Bundle 'spf13/vim-colors' " Bundle 'gorodinskiy/vim-coloresque' " Bundle 'flazz/vim-colorschemes' " Bundle 'skammer/vim-css-color' And then enable them one at a time to isolate.
vim colors not automatically loaded (probable Vundle conflict)
1,459,528,977,000
I'm trying to run a command using screen which contains the dollar sign, but the dollar sign does not get through. screen -d -m echo \$ > test.txt test.txt just ends up being an empty file...
You're redirecting the output of screen. That's why test.txt is empty. In fact, the $ is passed as an argument to echo. The shell you're calling screen from sees \$, resulting in the one-character string $ being an argument of echo. Screen runs echo which displays a $ in the screen window. Immediately after that, the program returns and so the window closes. Note that if you want to use shell constructs for what is executed in the screen window, you'll need to invoke a shell explicitly. screen -d -m sh -c 'echo \$ >test.txt'
Screen escape dollar sign
1,459,528,977,000
I am working on a collectd plugin to monitor a program I have running in a detached screen session. This program constantly updates the terminal with its status by replacing its old status (similar to programs like top, etc). I would like to be able to grab what it is currently "showing" and parse it to get the current status of the program. I know there is a way to send text to a screen, but is there a way to grab it? Alternatively, is there another program/approach to accomplish what I am looking for?
That'd be the hardcopy command. screen -x yoursession -X hardcopy /path/to/your/file Would cap what the terminal is currently showing, without backlog, to the given file.
Grab text from detached screen [duplicate]
1,459,528,977,000
After I reattach screen session : screen -DR already_attached_session My previous terminal is broken with broken bash: [remote power detached] Warning: Program '/bin/bash' crashed. I can not recover it with Ctrl+C, Ctrl+Z, Ctrl+D. Any idea what goes wrong and how can I avoid it ? (reattach properly)
Try using the lowercase -d option instead of -D. The -D option is forceful.
After screen Reattaching, previous bash broken
1,459,528,977,000
Possible Duplicate: How can I disown it a running process and associate it to a new screen shell? I started a process from one ssh session to a target machine T. The system from which I ssh'ed, A, hung. I checked using ssh from another machine, B that the process is still running on T. Now I want to be able to restart A without affecting the run of the process on T. I had forgotten to use screen or byobu etc. Since A is currently hung, I cant even do a ctrl z and disown or something. What can be done ? I dont want the process to terminate but I want to be able to restart A which has hung.
You could try to send a SIGCONT signal to the process, but as rozcietrzewiacz mentions, you may need to do some trickery with file descriptors if the process requires terminal access. kill -CONT pid If this still comes up as T, then it likely needs user input.
Is it possible to detach a process started from one ssh session using another ssh session? [duplicate]
1,459,528,977,000
When I execute the command screen -S myscreen -X stuff $'search add $1 \015' from a shell it works perfectly. If I put it in a .sh file and run it as sh /test.sh variablehere it sends it to screen as $'search add variablehere'. Why would it normally work but not from sh? Im on Ubuntu Server if it matters.
The expression $'search add $1 \015', and in general the quoting $'string' is a bash features (probably also of other shells), so it works from command line, where you probably are using bash. It for sure do not work for sh, that in ubuntu points to dash. So the simple solution is to invoke your script with bash ./test.sh.
Return Carriage not working (Screen)
1,459,528,977,000
In gnu screen I can set the window title using Ctrl-a Shift-a <name>. When I am inside bash prompt I can determine whether I am inside screen by checking the variable $STY. Can I check some variable and determine the name of the currently open window?
There's not a variable for the current window title, but $WINDOW has the window number which I believe can be used in any command that takes the title. If you just want to see the window title, then C-a N (Ctrl+a,N) will show the current window number and (title) in the message line (typically appears in the bottom left for a couple of seconds and disappears).
How to get the current window name in bash inside screen
1,459,528,977,000
On Linux the DPI (dot per inch) is set to 96 per default, it can be changed globally on the X start up parameter for instance X -dpi 120 This seem to mainly impact text/font scaling. In comparison when screen resolution (ex 1920x1080) is changed this impact everything (window/text/image/etc). Is DPI meant only for text scaling?
DPI DPI stand for dots per inch and is a measure of spatial printing/display, in particular the number of individual dots that can be placed in a line within the span of 1 inch (2.54 cm). Computer's screens do not have dots, but do have pixels, the closely related concept is pixels per inch or PPI and thus DPI is implemented with the PPI concept. The default 96 DPI mesure mean 96x96 vertically and horizontally. Additionally What is DPI and when does it matter? video is very informative. Resolution A native screen resolution, represent the number of pixels (X,Y horizontally and vertically) that a screen have physically. For instance a Full HD screen 1920x1080 have a count of 1920 physical pixel horizontally and a count of 1080 physical pixel vertically which mean 2073600 pixels in total for the whole screen. Compared to the DPI (dots per inch), the resolution is not linked at all to a physical size measurement but is just an horizontal/vertical pixel count. Xorg, DPI and Resolution The X server needs, gets and uses the real/guessed screen spatial measurement along with its resolution in order to implement the DPI/PPI feature. On a desktop configuration we do use a screen resolution and a DPI/PPI value, each displayed element (text, application, etc) does implement a sizing mechanism to display its content, most of the time pixels are used this is why the DPI setting does not impact most windows size, because they are implementing a pixel measurement not DPI. On the other hand text/font does implement the DPI/PPI measurement and their size get changed when the DPI value is changed. Commands and configuration Changing the DPI with SDDM: # Edit /etc/sddm.conf with the following [X11] ServerArguments=-nolisten tcp -dpi 120 Changing the DPI with Lightdm: # Edit /etc/lightdm/lightdm.conf.d/lightdm.conf with the following [SeatDefaults] xserver-command=X -dpi 120 Get the current DPI xdpyinfo | grep dots xrdb -query | grep dpi Get the screen measurement # Note that xrandr Xorg extension does not display an accurate measurement xrandr | grep -w connected # alternative xdpyinfo | grep -B2 resolution Get an accurate screen measurement (sudo/root required) monitor-edid # or monitor-edid | monitor-parse-edid # or get-edid | parse-edid Links: 1, 2, 3
Is X DPI (dot per inch) setting just meant for text scaling?
1,459,528,977,000
I can login to the server terminal with username and password. But I can't run the screen command. It says Must be connected to a terminal while I ran this screen -R newNodeServer. I found an answer at Ask Ubuntu: What does the script /dev/null do?, but if I run the command script /dev/null according to that answer, will the running server, websites, and applications be affected? I am going to run some artisan commands for Laravel in screens. Such as php artisan queue and php artisan websockets:serve
My best guess here is: @testteam is trying to run screen command and getting screen complaining about not being able to open terminal. In the answer linked, solution mentioned is to use script /dev/null and that should resolve the issue. @testteam is wondering if that's going to affect any servers running on the machine (probably in the screen session). This answer has very good explanation what script command is going to do and why screen is complaining: Why this works is invoking script has a side effect of creating a pseudo-terminal for you at /dev/pts/X. This way you don't have to do it yourself, and screen won't have permission issues - if you su from user A to user B, by directly invoking screen you try to grab possession of user A's pseudo-terminal. This won't succeed unless you're root. So the fact that script solves the issue with screen is basically side effect. I'm guessing that you want to run some node.js app in the screen session. The fact that you created pts device and used script for that should not affect servers or (web)apps running inside screen session.
Will the command `script /dev/null` stop or affect the running applications and server? [duplicate]
1,459,528,977,000
I'm writing a script that spawns a screen process but depends on some pre-conditions I intend to perform before attaching to it. I noticed that when started in detached mode it does not recognize the $TERM, but I do not want to hardcode it on .screenrc, and I did not find anyone with the same problem. Here's my environment: $ screen --version Screen version 4.06.02 (GNU) 23-Oct-17 $ echo $TERM xterm-256color Here you can see it works as expected: $ screen -ADRS profile $ echo $TERM screen.xterm-256color But if done this way it goes all wrong: $ screen -dmS profile # I will perform some stuff here, then: $ screen -ADrS profile # here you can notice the colors have gone $ echo $TERM screen How can I spawn a detached screen but get the same $TERM behavior as it was in the first case, without hardcoding the term on .screenrc?
I think this is what you are (were) looking for: screen -dmS foo -T "screen.$TERM" I'm not sure if this solution is entirely general, but it should work fine as long as the parent-scope $TERM is properly set.
How to fix gnu screen term detection when started on detached mode?
1,459,528,977,000
So I have an automatic backup script hourly backing up important files of the server. It has many lines like this that send input to the screen session the game server console is running in to broadcast when it starts to backup the files: screen -x $SCREENNAME -X stuff "`printf "say Backing up world: \'$WORLD\'\r"` It works fine, unless I'm using a different window inside of the screen session. When I'm using a different window in the same screen session the script tries to execute the say Backing up world in the bash terminal I'm using which doesn't work and no message gets sent to the game console. Is there any way to direct the output to a specific screen inside the seesion. My game console is always on the first screen so screen 0. I'm on CentOS 7 if that's relevant
You can preselect a window by specifying -p , 0 is first window, 1 is second so on... screen -x $SCREENNAME -p 0 -X stuff "printf "say Backing up world: \'$WORLD\'\r""
Directing input made to a screen session with a command to a specific window inside the session?
1,459,528,977,000
When running Screen, I can use Ctrl+ac to create a new window and run vim in each window. Also from Screen, I can run the command screen vim multiple times to open new windows with vim already running. These work as expected. However... If I put the command multiple times in a script, such as: #!/bin/bash screen vim screen vim screen vim ...and run that script from within Screen, the first command will run as expected, but the second and following ones will not. Things I have noticed are: Window 2 and beyond does not have stty -ixon applied, which I have set in .bashrc If I don't have colorscheme set explicitly in .vimrc, it will use one scheme in window 1 and another in all following windows Sometimes a command will be skipped, i.e., sometimes only two new windows will be opened where the script was set to open three If I do a :windowlist, window 2 and following will not have the login flag set (running screen vim directly will set this flag), e.g., Num Name Flags 0 bash $ 1 vim $ <-- running the script from window 0 opened 1..3 (no flag on 2 or 3) 2 vim 3 vim 4 vim $ <-- manually running `screen vim` from window 0 always sets the flag Using Ctrl+aL on a window that's not logged in will return the message This window is not logged in and the flag will not be set. Pressing the keys again will then toggle between logged in and out (though stty -ixon etc' will still not be applied) Running htop will show all instances of vim (including ones that are not logged in) are running under my user. Why does manually opening multiple windows apply my settings correctly, but using a script doesn't? I am new to Linux and not sure if I'm doing something silly here.
I believe I found that the problem is caused by the script running all commands (except the first) in the background. I can force the first command to have the same problem by forking it with &. After not being able to find a way to have the script run each command in the foreground, one-after-the-other, I have found an alternative solution... I can put all the commands in a custom screenrc file (e.g., my_screenrc) as such: # Import default screenrc source ${HOME}/.screenrc # Run screen-specific commands (not bash ones) screen # Run bash in window 0 screen vim # Run vim in windows 1 through 3 (with correct settings) screen vim screen vim I can then run this from bash with: screen -c my_screenrc
Starting multiple Screen windows from shell script uses wrong configuration
1,459,528,977,000
Is there a single command for screen to completely close/quit all running programs in detached mode? I hope to do this in a bash script without any further input.
You can use screen -X to send a command to a running screen, so screen -X quit should ask the session to terminate and kill all of its windows. If you have multiple screens running, use -S to identify them.
Bash command to close all detached running programs by GNU screen?
1,459,528,977,000
#!/bin/bash set -o nounset set -o errexit trap 'echo "Aborting due to errexit on line $LINENO. Exit code: $?" >&2' ERR set -o errtrace set -o pipefail SCR="bunny" SCRIPT="/home/../run.sh" main() { if find_screen $SCR >/dev/null; then close_screen start_script fi } function start_script { echo "Starting script with new screen" screen -d -m -t $SCR sh $SCRIPT } function close_screen { if find_screen $SCR >/dev/null; then echo "Found! Deleting $SCR" screen -S -X $target_screen quit fi } function find_screen { if screen -ls "$1" | grep -o "^\s*[0-9]*\.$1[ "$'\t'"](" --color=NEVER -m 1 | grep -oh "[0-9]*\.$1" --color=NEVER -m 1 -q >/dev/null; then screen -ls "$1" | grep -o "^\s*[0-9]*\.$1[ "$'\t'"](" --color=NEVER -m 1 | grep -oh "[0-9]*\.$1" --color=NEVER -m 1 2>/dev/null return 0 else echo "$1" return 1 fi } target_screen=$(find_screen $SCR) main "$@" I am trying to create a script that restarts a specific screen. Now, the script does start the screen, but it also creates another screen with two dots 1234..randomName. The goal of the script is to: Check if screen exists If exists, close screen create a new screen session with SCRIPT name If it doesn't exist, create screen still! Not sure what's going or why it isn't working. What am I doing wrong?
I got this to work with a few modifications: #!/bin/bash set -o nounset # set -o errexit # trap 'echo "Aborting due to errexit on line $LINENO. Exit code: $?" >&2' ERR set -o errtrace set -o pipefail SCR="bunny" SCRIPT="/home/../run.sh" function main() { if find_screen $SCR >/dev/null; then close_screen start_script fi } function start_script { echo "Starting script with new screen" screen -d -m -S $SCR sh $SCRIPT } function close_screen { if find_screen $SCR >/dev/null; then echo "Found! Deleting $SCR" screen -S $target_screen -X quit fi } function find_screen { result=$(screen -ls "$1" | grep -o "^\s*[0-9]*\.$1[ "$'\t'"](" --color=NEVER -m 1 | grep -oh "[0-9]*\.$1" --color=NEVER -m 1) if [ -z $result ]; then echo "$1" return 1 else echo $result return 0 fi } target_screen=$(find_screen $SCR) main "$@" I commented out the following two lines: set -o errexit trap 'echo "Aborting due to errexit on line $LINENO. Exit code: $?" >&2' ERR These lines were interfering with your return 1 statement in the find_screen function In the close_screen function, screen -S -X $target_screen quit needed slight modification: screen -S $target_screen -X quit to match the switches with the respective parameters. The if statement in the find_screen function was never returning true, so I updated it slightly by adding a results variable, assigning it to your original test condition. The resulting update is as follows: result=$(screen -ls "$1" | grep -o "^\s*[0-9]*\.$1[ "$'\t'"](" --color=NEVER -m 1 | grep -oh "[0-9]*\.$1" --color=NEVER -m 1) if [ -z $result ]; then echo "$1" return 1 else echo $result return 0 fi Other items If you wish to name your screen based on the $SCR variable, you need to use the -S switch, as in screen -d -m -S $SCR ... and add whatever other parameters and switches, as desired. In the start_script function, looks like you're trying to use the -t switch, instead of -S, in screen -d -m -t $SCR sh $SCRIPT - based on your description, "create a new screen session with SCRIPT name" you would use -S to set the screen session name. You could combine this with -t to set the window name, as you may have multiple windows within a screen session: screen -d -m -S $SCR -tWindowName1
Close and restart screen - ends up being duped!
1,459,528,977,000
One useful feature of Emacs is the ability to save the layout of the current frame to a register C-x r f <letter> and restore it later C-x r j <letter>. In screen it can be a little tedious trying to reconstruct a layout after closing all but one buffer with C-a Q or something similar. From what I can gather screen does not have anything resembling emacs registers. I'm trying to figure out a way to simulate the emacs feature. Does screen have the ability to dump its current layout state to a file that can be read from later?
No - the only files which screen writes are enumerated in screen.h: #define DUMP_TERMCAP 0 /* WriteFile() options */ #define DUMP_HARDCOPY 1 #define DUMP_EXCHANGE 2 #define DUMP_SCROLLBACK 3 and those are documented in the manual page (none are the layout as such).
GNU screen mimic emacs frameset-to-register by writing layout to file
1,459,528,977,000
When the width of the currently focused pane (in the tmux sense) is too narrow to display the confirmation message Really quit and kill all your windows [y/n], Screen displays Width x chars too small and doesn't accept y or n. Is there a way to get it to either display a truncated y/n message or disable the confirmation altogether?
There's not much to work with, without modifying screen. The latter message comes from Input, and simply returns without providing a status code (see source): if (len < 0) { LMsg(0, "Width %d chars too small", -len); return; } Interestingly, that section was rewritten last year, removing the test but only commenting: Use size_t for len. Likely the reason for removal was to fix a compiler warning (size_t is positive). The ChangeLog does not mention this change; it may not even have been intentional: +Version 4.3.0 (13/06/2015): + * Introduce Xx string escape showing the executed command of a window + * Implement dead/zombie window polling, allowing for auto reconnecting + * Allow setting hardstatus on first line + + New Commands: + * 'sort' command sorting windows by title + * 'bumpleft', 'bumpright' - manually move windows on window list + * 'collapse' removing numbering 'gaps' between windows, by renumbering + * 'windows' command now accepts arguments for use with querying + So the most recent version (4.3.1) would not behave as you report. At least, it will not prevent you from using the input-prompt.
GNU screen prevent "Width x chars too small" message on exit ("C-a C-\")