date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,339,090,327,000
I saw some body split their window to 2x2, I just want to know how to do that? I know the 'split' command in Screen can only split the window horizontally.
GNU Screen <4.01 may not support vertical split without a patch. GNU Screen >4.01 supports vertical splitting. The Patch is licensed under GPLv2. Some people say that the vertical split in GNU screen makes the application slow but I haven't tested. I use tmux (terminal multiplexer)
How to split window vertically in GNU Screen?
1,339,090,327,000
Somehow I managed to close a screen window without screen 'noticing' it, so the session is still flagged as attached. This prevents me from re-attaching to this session. What can I do? me@iupr-serv8:~$ screen -r There are several suitable screens on: 25028.pts-19.XXX-serv8 (01/05/2012 07:15:34 PM) (Attached) 24658.pts-19.XXX-serv8 (01/05/2012 07:11:38 PM) (Detached) 24509.pts-19.XXX-serv8 (01/05/2012 07:10:00 PM) (Detached) 18676.pts-5.XXX-serv8 (01/02/2012 06:55:33 PM) (Attached) Type "screen [-d] -r [pid.]tty.host" to resume one of them. me@XXX-serv8:~$ screen -r 25028 There is a screen on: 25028.pts-19.XXX-serv8 (01/05/2012 07:15:33 PM) (Attached) There is no screen to be resumed matching 25028. [update] In the end I found out, that the session was not lost, but the ID of the first session is 0. The second session than has the ID 1.
Try detaching it first with screen -d. If that doesn't work, you can try, in increasing order of emphasis, -d|-D [pid.tty.host] does not start screen, but detaches the elsewhere running screen session. It has the same effect as typing "C-a d" from screen's controlling terminal. -D is the equivalent to the power detach key. If no session can be detached, this option is ignored. In combination with the -r/-R option more powerful effects can be achieved: -d -r Reattach a session and if necessary detach it first. -d -R Reattach a session and if necessary detach or even create it first. -d -RR Reattach a session and if necessary detach or create it. Use the first session if more than one session is available. -D -r Reattach a session. If necessary detach and logout remotely first. -D -R Attach here and now. In detail this means: If a session is running, then reattach. If necessary detach and logout remotely first. If it was not running create it and notify the user. This is the author's favorite. -D -RR Attach here and now. Whatever that means, just do it.
How to recover a 'lost' screen session?
1,339,090,327,000
I am inside a screen (screen -Ra). I have a long command, and I am at the end. Instead of keeping the left arrow, how can you go to the beginning of the line? CTRL-A works when I am in a normal window, but when I am inside a screen pressing CTRL-A gives me a message "No other window" - seems like CTRL-A is dispatched to the screen. How do you go to the beginning of a line in a screen?
Use Ctrl-a a, or change screen's escape keystroke (option -e).
Shell: how to go to the beginning of line when you are inside a screen?
1,339,090,327,000
I recently moved from GNU screen to tmux. I find it quite similar but with bigger support (I switched due to problem with escape-time in neovim- resolution was only for tmux). Unfortunately in tmux I'm unable to find a similar command to this: screen -X eval "chdir $(some_dir)" The command above changed the default directory for new window/screen/pane from within the GNU screen so when I pressed Ctrl+a (similar to tmux Ctrl+b)- new window opened in the $(some_dir) directory. Is there a similar thing in tmux? ANSWER: I have used @Lqueryvg answer and combined it with @Vincent Nivoliers suggestion froma a comment and that gave me a new binding for a command attach -c "#{pane_current_path}" which sets my current directory as a default one. Thanks.
tl;dr Ctrl+b : attach -c desired/directory/path Long Answer Start tmux as follows: (cd /aaa/bbb; tmux) Now, any new windows (or panes) you create will start in directory /aaa/bbb, regardless of the current directory of the current pane. If you want to change the default directory once tmux is up and running, use attach-session with -c. Quoting from the tmux man page for attach-session: -c will set the session working directory (used for new windows) to working-directory. For example: Ctrl+b : attach -c /ddd/eee New windows (or panes) will now start in directory /ddd/eee, regardless of the directory of the current pane.
How to change default new window directory from within the tmux
1,339,090,327,000
I thought Moving tmux pane to window was the same question but it doesn't seem to be. Coming from using GNU screen regularly, I'm looking for tmux to do the same things. On of the things I do regularly is have a couple of different windows open, one with some code open in vim, and a couple of terminals windows open to test the code, and sometimes a window or two for various other things. I split the screen vertically and will often have the vim window in the top pane and then one of the other windows in the bottom bane. The main commands I then use are Ctrla,Tab to rotate among the panes and Ctrla,n to rotate between the windows within a pane. For instance, with vim in the top pane, I switch to the bottom pane and then rotate through the other terminals, doing whatever I need. The screen stays split the whole time. The problem is I can't find comparable capability to screen's Ctrla,n in tmux. Switching windows seems to not work inside a pane, but jumps entirely. If the screen is split the only two options seem to be to jump to some window that isn't split and then split it or to do a sub-split of a pane. Neither are what I was looking for. Suggestions (besides just sticking with screen)?
tmux and screen have different models so there is no exact equivalent. In screen terms, a split lets you display multiple windows at the same time. next (C-a n) rotates windows through the active part of the split; this lets you rotate “hidden” windows through the active region of the split. In tmux terms, a split divides a window into one or more panes. Each part of a split window is an individual pane, panes are never hidden (if a window is selected (visible) all its panes are, too), and a pane can only be used in a single split of one window (a pane can not be in multiple windows, and it can not be in multiple splits of the same window). There are commands to move panes around in (or between) windows, but not in an identical way to next in screen. You could use a binding like the following to arrange a similar effect: bind-key C-n swap-pane -s :+.top \; rotate-window -Ut :+ You will probably want to put this in your ~/.tmux.conf file, but you can just type/paste it after Prefix : to bind it in your current server instance. To use the binding, pick your “main window”, split it, create a “pane container” window immediately after the “main window”, then use the binding to rotate any pane in the “main window” among the group in the “pane container” window. Here is how you might create the setup: Pick a window to use as your “main window”. Start (e.g.) Vim in it. Split your “main window” into two panes. E.g. Prefix " (:split-window) You can use this pane as your testing window (or log viewer, or whatever). Create a new window (the “pane container”) immediately after your main window. E.g. Prefix c (:new-window) It is important that no other window gets between the indexes of the “main window” and the “pane container” window (+ in the window specifiers used in the bound commands means “the next higher numbered window”). Split this window into a number of panes. To rotate through three panes, split this window into two panes (the third pane is the one in the “main window”). Maybe you need a shell for git, and a shell for running a database interface. Put each in a separate pane in this “pane container” window. Switch back to your “main window”. Select the pane that you want to “rotate out”. You can use Prefix Up/Down/Left/Right to move among the panes. Invoke the binding to swap the current pane with the first pane in “pane container” window and (“behind the scenes”) rotate the panes inside the “pane container” window (so that the next time you run the binding, the first command swaps with the “next” pane in the sequence). Prefix Control-n (the binding use C-n, but you could change this to whatever you like). To scroll backwards through the panes, you can use the below: bind-key C-p swap-pane -s :+.bottom \; rotate-window -Dt :+
How do I cycle through panes inside a window in tmux like in screen?
1,339,090,327,000
As root, I'm connecting to a remote host to execute a command. Only "standarduser" has the appropriate id-file and correct .ssh/config, so I'm switching the user first: su standarduser -c 'ssh -x remotehost ./remotecommand' The command works fine, but despite the fact that I used "-x" (disable X11-Forwarding) and having X11Forwards disabled in /etc/ssh/ssh_config, I still get the error message: X11 connection rejected because of wrong authentication. I'm not getting the error message when I'm logged in as "standarduser". This is quite annoying as I would like to integrate the command in a cron job file. I understand that the error message refers to the wrong authentication of root's .XAuth file, but I'm not even trying to connect via X11. Why is "ssh -x" not disabling the X11 connection and throwing the error message? UPDATE: The message only shows when I'm logged in within a screen, when using the command stated above on the local machine itself (without screen), I don't get an error message, so this should be fine with cron, too. I also started the same command with -v and surprisingly got the error message FIRST, even before the status information from SSH: root@localhost:~# su standarduser -c 'ssh -x remotehost ./remotecommand' X11 connection rejected because of wrong authentication. OpenSSH_6.2p2 Ubuntu-6ubuntu0.1, OpenSSL 1.0.1e 11 Feb 2013 This led me to the problem itself, it is NOT the ssh which is throwing the error message, it's su: root@localhost:~# su standarduser -c 'echo Hi' X11 connection rejected because of wrong authentication. Hi Why do I only get this error within screen? How can I disable this error message?
Seems like your root lacks some X11 magic cookie in the .Xauthority, which your standarduser has. Here is how to fix this. SHORT VERSION (thanks to @Vladimir Panteleev) standarduser@localhost:~$ sudo xauth add $(xauth list | grep "unix$(echo $DISPLAY | cut -c10-12)") ORIGINAL LONG VERSION To fix things, first detect which display number standarduser uses: standarduser@localhost:~$ echo $DISPLAY localhost:21.0 In this case it is 21.0. Secondly, display standarduser's list of cookies: standarduser@localhost:~$ xauth list localhost/unix:1 MIT-MAGIC-COOKIE-1 51a3801fd7776704575752f09015c61d localhost/unix:21 MIT-MAGIC-COOKIE-1 0ba2913f8d9df0ee9eda295cad7b104f localhost/unix:22 MIT-MAGIC-COOKIE-1 22ba6595c270f20f6315c53e27958dfe localhost/unix:20 MIT-MAGIC-COOKIE-1 267f68b51726a8a381cfc10c91783a13 The cookie for the 21.0 display is the second in the list and ends with 104f. The last thing to do is to add this particular cookie to the root's .Xauthority. Log in as root and do the following: root@localhost:~$ xauth add localhost/unix:21 MIT-MAGIC-COOKIE-1 0ba2913f8d9df0ee9eda295cad7b104f This is how you can mitigate the X11 connection rejected because of wrong authentication error when you run su as a different user in Bash script or screen. Thanks to this guy for inspiration.
"su" with error "X11 connection rejected because of wrong authentication"
1,339,090,327,000
Currently I have a shell script which logs messages to a log file like this: log_file="/some/dir/log_file.log" echo "some text" >> $log_file do_some_command echo "more text" >> $log_file do_other_command When executing this script, there is no output to screen, and, since I'm connecting to the server via putty, I have to open another connection and do "tail -f log_file_path.log", because I can't terminate the running script and I want to see the output in real time. Obviously, what I want is that the text messages are printed on screen and into file, but I'd like to do it in one line, not two lines, one of which has no redirection to file. How to achieve this?
This works: command | tee -a "$log_file" tee saves input to a file (use -a to append rather than overwrite), and copies the input to standard output as well. Because the command can detect that it's now being run in a non-interactive fashion this may change its behaviour. The most common side effect is that it disables colour output. If this happens (and you want ANSI colour coded output) you have to check the command documentation to see if it has a way to force it to revert to the interactive behaviour, such as grep --color=always. Beware that this means the log file will also include these escape codes, and you'll need to use less --RAW-CONTROL-CHARS "$log_file" to read it without distracting escape code literals. Also beware that there is no way to make the log file contents different from what is printed to screen when running the above command, so you can't have colour coded output to screen and non-coloured output in the log file.
how to output text to both screen and file inside a shell script?
1,339,090,327,000
I'm trying to run a minecraft server on my unRAID server. The server will run in the shell, and then sit there waiting for input. To stop it, I need to type 'stop' and press enter, and then it'll save the world and gracefully exit, and I'm back in the shell. That all works if I run it via telnetting into the NAS box, but I want to run it directly on the box. this is what I previously had as a first attempt: #define USER_SCRIPT_LABEL Start Minecraft server #define USER_SCRIPT_DESCR Start minecraft server. needs sde2 mounted first cd /mnt/disk/sde2/MCunraid screen -d -m -S minecraft /usr/lib/java/bin/java -Xincgc -Xmx1024M -jar CraftBukkit.jar MCunraid is the folder where I have the Craftbukkit.jar and all the world files etc. If I type that screen line in directly, the screen does setup detached and the server launches. If I execute that line from within the script it doesn't seem to set up a screen for stopping the server, I need to 'type' in STOP and then press enter. My approach was screen -S minecraft -X stuff "stop $(echo -ne '\r')" to send to screen 'minecraft' the text s-t-o-p and a carriage return. But that doesn't work, even if I type it directly onto the command line. But if I 'screen -r' I can get to the screen with the server running, then type 'stop' and it shuts down properly. The server runs well if I telnet in and do it manually, just need to run it without being connected from my remote computer.
I can solve at least part of the problem: why the stop part isn't working. Experimentally, when you start a Screen session in detached mode (screen -d -m), no window is selected, so input later sent with screen -X stuff is just lost. You need to explicitly specify that you want to send the keystrokes to window 0 (-p 0). This is a good idea anyway, in case you happen to create other windows in that Screen session for whatever reason. screen -S minecraft -p 0 -X stuff "stop^M" (Screen translate ^M to control-M which is the character sent by the Enter key.) The problem with starting the session from a script is likely related to unMENU.
sending text input to a detached screen
1,339,090,327,000
I am running an application with command $ grails run-app which prints log in terminal like below. What I want is search a particular text (say user authorities) in this log so that I can verify further. One way using Logging Apis to write in text file but I want to search it in a terminal at the moment. I found similar question at how to make search a text on the terminal directly which suggests screen command, but I have no idea how screen works in this case. I tried $ screen grails run-app but couldn't move ahead. I can see screen lists with prayag@prayag:~/zlab/nioc2egdelonk$ screen -list There is a screen on: 8076.pts-2.prayag (10/06/2013 12:13:25 PM) (Attached) 1 Socket in /var/run/screen/S-prayag.
Ctrl+a (default screen command prefix), [ (enter copy mode) followed by ?SEARCH_TEXT seems to work. Press n to go to the next occurrence. From there, you can copy words, lines, regions, etc to dump into files or paste later on (with Ctrl+a, ]).
search text on the terminal output
1,339,090,327,000
I'm trying to force GNU screen to create a "virtual" terminal, without attaching to it, execute script inside and NOT terminate session once script ends. I tried many combinations, including: screen -dmS udplistener /share/Sys/autorun/start_udp_listeners.sh or screen -S udplistener -X /share/Sys/autorun/start_udp_listeners.sh and none of them worked. I either get session without executed script, script executes, but session is terminated once it finishes or I'm getting "No screen session found" error. What I'm basically trying to do is to run UDP listener, written in PHP and make it work in infinte loop (don't break listening). Yes -- I could run PHP script with & at the end, forcing PHP CLI to run as daemon. The problem is, that I'm using a piece of junk called server (QNAP -- never, ever buy this junk!) which does seems to be ignoring this. As soon as I logoff SSH session, scripts stops. So screen seems to be the only option. But I can't understand, why it terminates session once executed command or script ends? EDIT: I've also tried example found in the Internet: screen -dmS name screen -S name -p windowname -X stuff 'mc ' No lack! After attaching to it (screen -R name) I see that Midnight Commander HASN'T been executed. Though example author said, it will be.
To keep screen busy after the script completes, just keep something persistent running in a window. The simplest choice for that "something" is probably an interactive shell. Here's one way to do it (assuming bash as the choice of interactive shell): screen -dmS session_name sh -c '/share/Sys/autorun/start_udp_listeners.sh; exec bash' -dm: starts screen in detached mode -S: sets session name for screen for easier retrieval later on sh -c '...': instead of simply running your script, which will terminate, use sh -c to run multiple commands exec bash: after the script terminates, the sh from above will switch over to an interactive shell (bash), which should never exit until something external terminates it. This will keep screen open as long as the bash instance is alive.
Prevent GNU screen from terminating session once executed script ends
1,339,090,327,000
I would like to force GNU screen to reflow to the existing terminal width when I reattach a session. It seems to me this worked properly before I upgraded a machine to CentOS 6, but I cannot figure out how to restore it. (TERM=xterm) Whenever I reattach a session, regardless of state when I detached it, it launches at 80 columns, resizing my terminal (PuTTY, in this case) along with it. I'm launching & reattaching with: screen -aA -R <session> My .screenrc contains only the following, and a few irrelevant key bindings: term xterm defscrollback 10000 # status line at the bottom hardstatus on hardstatus alwayslastline hardstatus string "${-}%{.0c}%-w%{.y0}%f%n %t%{-}%+w %=%{..G}[%H] %{..Y} %D %M %d, %Y %c | Load: %l" caption splitonly "%{.yK}%3n t" caption string "%{.c0}%3n %t" vbell off # Fix fullscreen programs altscreen on
after you reattach a ctrl-a F runs the "fit" command to resize the current window. if you reattach using the -A option it should resize all windows when you reattach. Are there others still attached to the screen session when you are attaching? For instance, are you having to use -x to reattach instead of -r? you can detach others when you reattach with "screen -D -r" instead of "screen -x", and I'd expect this to automatically refit windows.
Force GNU screen to reflow to current terminal width on reattach?
1,339,090,327,000
When I start screen, I get a message giving the version, copyright, and bug-reporting email address. I don't want to see this every time I start screen. Searching the man page didn't seem to result in a solution, and I am hoping that the experts here know a way to bypass this info page.
There's a setting for that: # Don't display the copyright page startup_message off # default: on You can set that system-wide (in /etc/screenrc) or only for your account (in ~/.screenrc). Shortcut commands: # Skipping the startup message for your account. echo 'startup_message off' >> ~/.screenrc # Skipping the startup message for all accounts. sudo bash -c "echo 'startup_message off' >> /etc/screenrc"
How do you bypass or skip the intro message when starting screen?
1,339,090,327,000
I make heavy use of screen's "log" command to log the output of a session to a file, when I am making changes in a given environment. I searched through tmux's man page, but couldn't find an equivalent. Is anyone aware of a similar feature in tmux, or do I have to write my own wrapper scripts to do this? EDIT: I'm aware of 'script' and other utilities that allow me to log a session. The reason that screen's functionality is so useful is the ability to define a logfile variable which uses string escapes to uniquely identify each session. e.g. I have a shell function which, given a hostname, will SSH to that host in a new screen window and set the window title to the hostname. When I start a log of that session, it is prefixed with the window title. If this functionality doesn't exist in tmux, I'll have to create a new set of shell functions to set up 'scripts' of sessions I want to log. This isn't hugely difficult, but it may not be worth the effort given that screen does exactly what I need already.
Let me see if I have deciphered your screen configuration correctly: You use something like logfile "%t-screen.log" (probably in a .screenrc file) to configure the name of the log file that will be started later. You use the title <hostname> (C-a A) screen command to set the title of a new window, or you do screen -t <hostname> ssh0 <hostname> to start a new screen session. You use the C-a H (C-a :log) screen command to toggle logging to the configured file. If so, then is nearly equivalent (requires tmux 1.3+ to support #W in the pipe-pane shell command; pipe-pane is available in tmux 1.0+): In a configuration file (e.g. .tmux.conf): bind-key H pipe-pane -o "exec cat >>$HOME/'#W-tmux.log'" Use tmux rename-window <hostname> (C-b ,) to rename an existing window, or use tmux new-window -n <hostname> 'ssh <hostname>' to start a new tmux window, or use tmux new-session -n <hostname> 'ssh <hostname>' to start a new tmux session. Use C-b H to toggle the logging. There is no notification that the log has been toggled, but you could add one if you wanted: bind-key H pipe-pane -o "exec cat >>$HOME/'#W-tmux.log'" \; display-message 'Toggled logging to $HOME/#W-tmux.log' Note: The above line is shown as if it were in a configuration file (either .tmux.conf or one you source). tmux needs to see both the backslash and the semicolon; if you want to configure this from the a shell (e.g. tmux bind-key …), then you will have to escape or quote both characters appropriately so that they are delivered to tmux intact. There does not seem to be a convenient way to show different messages for toggling on/off when using only a single binding (you might be able to rig something up with if-shell, but it would probably be ugly). If two bindings are acceptable, then try this: bind-key H pipe-pane "exec cat >>$HOME/'#W-tmux.log'" \; display-message 'Started logging to $HOME/#W-tmux.log' bind-key h pipe-pane \; display-message 'Ended logging to $HOME/#W-tmux.log'
Is there an equivalent of GNU Screen's "log" command in tmux?
1,339,090,327,000
I am using screen to split my terminals but I would like to be able to resize the horizontal dimension of the split screens. If I do C-a :resize 10 I only change the vertical dimension to 10 lines. How do I achieve the same but for the horizontal dimension?
At least on Debian and Ubuntu, the resize command, when applied to a full height region performs a horizontal resizing. If it works for you, then first split vertically, next perform a resizing of the width, then split horizontally.
how to resize horizontally a screen region
1,339,090,327,000
when starts session named any name like this screen -S name1 i want to open tabs windows in this screen session like when open tabs in gnome-terminal like this gnome-terminal --tab -e "some commands" so how to do this ?
1. Tabs in screen You're looking for this to add to your .screenrc file: screen -t tab1 screen -t tab2 Here's a nice basic .screenrc to get you started with a status bar etc. NOTE: This is typically located in your home directory /home/<username>/.screenrc. screen -t validate #rtorrent screen -t compile #irssi screen -t bash3 screen -t bash4 screen -t bash5 altscreen on term screen-256color bind ',' prev bind '.' next # #change the hardstatus settings to give an window list at the bottom of the #screen, with the time and date and with the current window highlighted hardstatus alwayslastline #hardstatus string '%{= kG}%-Lw%{= kW}%50> %n%f* %t%{= kG}%+Lw%< %{= kG}%-=%c:%s%{-}' hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W}%c %{g}]' screenshot 2. Tabs in screen (with commands run inside) The example .screenrc below will create 2 tabs and run 3 echo commands in each. screen -t tab1 select 0 stuff "echo 'tab1 cmd1'; echo 'tab1 cmd2'; echo 'tab1 cmd3'^M" screen -t tab2 select 1 stuff "echo 'tab2 cmd1'; echo 'tab2 cmd2'; echo 'tab2 cmd3'^M" altscreen on term screen-256color bind ',' prev bind '.' next # #change the hardstatus settings to give an window list at the bottom of the #screen, with the time and date and with the current window highlighted hardstatus alwayslastline #hardstatus string '%{= kG}%-Lw%{= kW}%50> %n%f* %t%{= kG}%+Lw%< %{= kG}%-=%c:%s%{-}' hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W}%c %{g}]' This technique makes use of screen's select and stuff commands to initially select one of the tabs, and then "stuff" a string into it. screenshot 3. Creating #2 without using a .screenrc file If you're looking for the scenario where you can: create a screen session load it up with tabs have each tab running their own commands not require a .screenrc file Then this is the one for you! Be prepared though. This one can get a little tricky with the command lines. For starters let's create a screen session: $ screen -AdmS myshell -t tab0 bash The switches -AdmS do the following: (See the screen man page for more details) -A Adapt the sizes of all windows to the size of the current terminal. By default, screen tries to restore its old window sizes when attaching to resizable terminals -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. -S sessionname When creating a new session, this option can be used to specify a meaningful name for the session. This name identifies the session for "screen -list" and "screen -r" actions. It substitutes the default [tty.host] suffix. Now let's start loading it up with tabs + their commands: $ screen -S myshell -X screen -t tab1 vim $ screen -S myshell -X screen -t tab2 ping www.google.com $ screen -S myshell -X screen -t tab3 bash These 3 commands will create 3 additional tabs and run vim, ping google, and launch a bash shell. If we list out the screen sessions we'll see the following: $ screen -ls There is a screen on: 26642.myshell (Detached) 1 Socket in /var/run/screen/S-root. If we connect to the screen session, myshell, and list the tabs that it contains we'll see the following: $ screen -r myshell Hit this key combination: Ctrl+A followed by Shift+" Num Name Flags 0 tab0 $ 1 tab1 $ 2 tab2 $ 3 tab3 $ Switching to tab2: 64 bytes from ord08s08-in-f20.1e100.net (74.125.225.116): icmp_seq=443 ttl=55 time=41.4 ms 64 bytes from ord08s08-in-f20.1e100.net (74.125.225.116): icmp_seq=444 ttl=55 time=33.0 ms 64 bytes from ord08s08-in-f20.1e100.net (74.125.225.116): icmp_seq=445 ttl=55 time=30.1 ms screenshot The above commands are the basic way to accomplish what the OP was looking for. This of course can be condensed and refined using Bash aliases or even shell scripts, this is merely to demonstrate the capability and show the way! References Screen man page
How to open tabs windows in Gnu-screen & execute commands within each one
1,339,090,327,000
I have a screen instance running, and I would need to execute some code inside the screen, and get the result out to my script. The first part is quite easy, I just screen -S session_name -X eval 'stuff "$cmd"\015'. (I modified a line I found in a script) The second part, getting out the output, is trickier. How can I get the whole output, whatever it's size?
You could start screen with the -L option. This will cause screen to create a file screenlog.n (the n part is numerical, starting with a zero) in the current working directory. In your case this would look something like: screen -S session_name -L -X eval 'stuff "$cmd"\015' As long as you remember to clean up afterwards, this should match what you are after. For last line of the log, it can easily be obtained with tail -1 screenlog.0, or the entire log can be parsed however you wish.
How to get the output inside `screen` out to a script?
1,339,090,327,000
Is it possible to persist the "state" of a GNU screen window (or just a standard shell) so that I can reload everything after a reboot: The number of opened shells The name of each shell The current directory of each shell The history of each shell If possible, their environment variables
It is not really possible to save a complete screen session. What you can do is to create a proper .screenrc which will setup some things after you restarted your system. Here are some comments to the things you listed: The number of opened shells The name of each shell The current directory of each shell I use something like this in my .screenrc to open some specific shells on startup: ## set the default shell shell zsh # screens screen -t 'zsh' screen -t 'mutt' mutt screen -t 'zsh' /home/user/bin/scriptToRun [..] You will get the string between '' as your window name and the command after the name will be executed on your default shell. Include any script you want, for example change in a specific directory and open some logs. The history of each shell Have you ever thought about sharing the history of the shells across your sessions? IMHO this makes things much more easier. In ZSH its done with setopt SHARE_HISTORY in your .zshrc If possible, their environment variables If you really need this and don't want any trade-off you could think about a shell script, which reads out the current state of screen, saves the number of shells, environment variables, etc. and puts this information in a startup script called by your .screenrc. For me this would not be worth the effort because I appreciate a clean environment after a reboot, if I can customize the default windows for screen.
Save complete GNU screen session state
1,339,090,327,000
I've been using screen -dRaA -S x to open up a single session between different workstations as I move about. Handy. Is it possible to connect multiple times to a single session, though, without disconnecting others? When I have two machines I'm quickly moving between even reconnecting starts to slow me down.
Try screen -aAxR -S x -x is the option that does what you want.
Attach multiple times to a single screen session
1,339,090,327,000
I am setting up a server where there are multiple developers working on multiple applications. I have figured out how to give certain developers shared access to the necessary application directories using the setgid bit and default ACLs to give anyone in a group access. Many of these applications run under a terminal while in development for easy access. When I work alone, I set up a user for an application and run screen as that user. This has the downside that every developer to use the screen session needs to know the password and it is harder to keep user and application accounts separate. One way that could work is using screen multiuser features. They do not work out-of-the-box however, screen complains about needing suid root. Does giving that have any downsides? I am pretty careful about using suid root anything. Maybe there is a reason why it isn't the default? Should I do it with screen or is there some other intelligent way of doing what I want?
Yes, you can do it with screen which has multiuser support. First, create a new session: screen -d -m -S multisession Attach to it: screen -r multisession Turn on multiuser support: Press Ctrl-a and type (NOTE: Ctrl+a is needed just before each single command, i.e. twice here) :multiuser on :acladd USER ← use username of user you want to give access to your screen Now, Ctrl-a d and list the sessions: $ screen -ls There is a screen on: 4791.multisession (Multi, detached) You now have a multiuser screen session. Give the name multisession to acl'd user, so he can attach to it: screen -x youruser/multisession And that's it. The only drawback is that screen must run as suid root. But as far as I know is the default, normal situation. Another option is to do screen -S $screen_id -X multiuser on, screen -S $screen_id -X acladd authorized_user Hope this helps.
Sharing a terminal with multiple users (with screen or otherwise)
1,339,090,327,000
I want to run a bash script in a detached screen. The script calls a program a few times, each of which takes too long to wait. My first thought was to simply open a screen and then call the script, but it appears that I can't detach (by ctrl-a d) while the script is running. So I did some research and found this instruction to replace the shebang with following: #!/usr/bin/screen -d -m -S screenName /bin/bash But that doesn't work, either (the options are not recognized). Any suggestions? PS It occurs to me just now that screen -dmS name ./script.sh would probably work for my purposes, but I'm still curious about how to incorporate this into the script. Thank you.
The shebang line you've seen may work on some unix variants, but not on Linux. Linux's shebang lines are limited: you can only have one option. The whole string -d -m -S screenName /bin/bash is passed as a single option to screen, instead of being passed as different words. If you want to run a script inside screen and not mess around with multiple files or quoting, you can make the script a shell script which invokes screen if not already inside screen. #!/bin/sh if [ -z "$STY" ]; then exec screen -dm -S screenName /bin/bash "$0"; fi do_stuff more_stuff
Run script in a screen
1,339,090,327,000
I am using screen /dev/tty-MyDevice to look at traffic on my serial port. Pressing Ctrl+D does not cause the screen to terminate. What I have to do in order to terminate it?
Use the screen quit command (normally ctrl-A \).
terminate screen monitoring serial port
1,339,090,327,000
I have a shared home directory that is automounted via NFS on all the UNIX servers I log in to. I would like to have a single .screenrc that (for example) puts the hostname in the hardstatus line in a different colour to indicate when I am logged on to production versus development; our hostnames are such that this can easily be done through the use of pattern matching. Is there any way of putting conditional statements into .screenrc? A quick grep of the man page doesn't seem to reveal anything obvious. EDIT: To clarify, I already have a custom hard status line; I want to change some of the colouring/fields displayed based on the hostname that screen is invoked on. I already have something like this for my PS1, however I would rather do this in the screen status line as I jump off from these hosts to routers/switches, which don't allow me to do any prompt colourisation. This way, I can have one window for production, and one for development, with the colour of the screen status line telling me which one I am on at a glance.
I see two way to do this, the first one is to make a .screenrc file by host. Like .screenrc_serverA, .screenrc_serverB, ... In your shell startup script set SCREENRC to something like .screenrc_`hostname` Of course you can use the source command of screen to include something like .screenrc_default in each custom .screenrc_… files so that they only contains a caption/hardstatus line and not the whole configuration each time. The second way would be to execute commands like screen -X hardstatus lastline ... (using if tests to execute the command with different value for ... depending of the hostname) in your shell startup script. When you will log on the server, screen -X will do nothing because screen will not yet be launched, but each time you open a new windows in screen the hardstatus will be updated. Of course the 1st solution is better because the second one will refresh the hardstatus line each time you opened a news windows which is probably useless as the hostname will not have changed.
How can you change the GNU screen status line based on hostname?
1,339,090,327,000
I have a window called 'Codes' in window 1, and I want to move it to window 7, is it possible?
Yes, it is possible. Go to window 1, type the command character (e.g. CTRL-A) and then type: :number 7. If there is already a window at 7, then the two windows will be swapped (window 7 will become window 1). From the manpage: Change the current windows number. If the given number n is already used by another window, both windows exchange their numbers. If no argument is specified, the current window number (and title) is shown.
How to move window in GNU Screen
1,339,090,327,000
I have noticed that a logoff (log out) from my X user session will kill any tmux session I have initiated, even sessions I had run with sudo tmux and similar commands. I am sure that this formerly did not happen, but some recent change has effected this behavior. How do I maintain these tmux (or screen) sessions, even after I end my X session?
This "feature" has existed in systemd previously, but the systemd developers decided to effect a change in the default, to enable the setting for termination of child processes upon log out of a session. You can revert this setting in your logind.conf (/etc/systemd/logind.conf): KillUserProcesses=no You can also run tmux with a systemd-run wrapper like the following: systemd-run --scope --user tmux For these systems, you may just want to alias the tmux (or screen) command: alias tmux="systemd-run --scope --user tmux"
Prevent Logoff from Killing tmux Session
1,339,090,327,000
Every now and then some key combination clears my working (Gnu) screen and brings up this message: Screen used by <username> on host01 Password: What key combination causes this and what does it signify?
According to this source it's the key combination Ctrl+a and then x. It signifies locking the screen and unlocking it with your password.
What triggers this screen prompt "Screen used by <username> on host01."?
1,339,090,327,000
I love screen, but it drives me nuts that I have to stop typing input, hit CTRL+A [, and then find what I need. Is there a way to make the scroll wheel function normally, rather than scrolling commands? Also, is it possible to enable Shift+PageUp/PageDn?
I use these settings with urxvt in my ~/.screenrc: termcapinfo rxvt-unicode ti@:te@ termcapinfo rxvt ti@:te@ termcapinfo rxvt 'hs:ts=\E]2;:fs=07:ds=\E]2;screen07' Those allow for scrollbar and mouse wheel to do "the right thing™". Note that this is dependent on terminal type, so will not work if your terminal is not of type rxvt. If it doesn't work, try replacing rxvt and rxvt-unicode with the appropriate terminal type (get this by running printf $TERM.)
Is there a way to make Screen scroll like a normal terminal?
1,339,090,327,000
Let's say I have several shell "tabs" (or screens? sessions?) named bash1, bash2, etc. open in GNU screen. I want the status bar (i.e., the caption line) to display the names as "bash1 | bash2 | ..", with the currently open tab and the last open tab clearly marked. How do I make this happen with my .screenrc?
Edit or create (if not present) /etc/screenrc or (~/.screenrc) and add below code autodetach on startup_message off hardstatus alwayslastline shelltitle 'bash' hardstatus string '%{gk}[%{wk}%?%-Lw%?%{=b kR}(%{W}%n*%f %t%?(%u)%?%{=b kR})%{= w}%?%+Lw%?%? %{g}][%{d}%l%{g}][ %{= w}%Y/%m/%d %0C:%s%a%{g} ]%{W}' shelltitle 'bash' can be changed once the screen is created. (Ctrla + A) session name can be changed to SESSSIONNAME with :sessionname SESSIONNAME.
GNU screen status bar - how to make it display shell session names?
1,339,090,327,000
I'd like to be able to check progress and output of my existing screen sessions, but in a read-only manner, so as to prevent something from going wrong due to user error. Is there a way to do this?
Unfortunately, I think the answer is no. The asker of this question switched to tmux specifically because it has that feature (you pass the -r flag when attaching), so if you have the option to switch multiplexers it's probably your best choice
Is there a way to run 'screen' in read-only mode?
1,339,090,327,000
To navigate to the starting and end of a command, I usually use Ctrla and Ctrle. However, when I work within a GNU screen, those keybinding do not work becuase perhaps they are being used by the GNU screen. Is there another way to move to the starting or the end of the command? I am on CentOS6.2
Ctrl-A followed by the letter 'a' will send the Ctrl-A sequence to the shell. Or you could map the screen command key to something other than Ctrl-A
Ctrl-a does not take me to the beginning of the prompt while I am working within a GNU screen
1,339,090,327,000
When I do this in my terminal: echo -e "\xF0\x9f\x8d\xba" I get a cool beer mug in my terminal: üç∫ However, when I start screen, and try the same, I'm getting a ÔøΩ. How do I get the nice beer mug? This is my .screenrc: nethack on startup_message off defscrollback 3000 hardstatus on hardstatus alwayslastline hardstatus string "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G} %H %{..Y} %m/%d %c" termcapinfo xterm 'bc@:bs@' ignorecase on maptimeout 0 vbell off defutf8 on defencoding utf8 Also running screen with the -U option doesn't help.
It's a apparently a known bug: No characters beyond the BMP are displayed, as screen apparently only has a two byte buffer for characters. (It works in tmux).
GNU Screen doesn't echo unicode characters correct
1,337,145,221,000
Both terminal multiplexers (screen, tmux) and keyboard-driven tiling window managers (ratpoison, dwm, xmonad) provide similar functionality. Is there any benefit in using both at the same time? What about problems that may arise?
I use dwm and tmux. Before learning to use tmux, I would have multiple terminals open for different things, and have them in different tags. Now I can run everything inside of one tmux session, under a single tag, and can detach and reattach without losing state if I need to restart X.
Does a terminal multiplexer have any benefit when used with a tiling window manager?
1,337,145,221,000
While using Xorg X11, on KDE/Gnome/XFCE how can we scale the display/resolution for the whole desktop and/or per application? (when this is not available on the settings GUI) The purpose is to keep the screen resolution unchanged (at max) while scaling the size (bigger/smaller) of the desktop/applications.
Linux display This is detailed in depth on how does Linux's display works? QA. On most desktops system (like KDE or Gnome) there are settings available on their respective settings panel, this guide is for additional/manual settings that can be applied to scale an application or the whole desktop. This reference article have many valuable informations for the matter. Scaling applications Scaling application can be done mainly via DPI, specific environment variable (explained bellow), application own setting or some specific desktop setting (out of scope of this QA). Qt applications can be scaled with the following environment variables, note that many applications are hard-coding sizing and font and thus the result on such app may not be as expected. export QT_AUTO_SCREEN_SET_FACTOR=0 export QT_SCALE_FACTOR=2 export QT_FONT_DPI=96 Gnome/GTK applications can be scaled with the following environment variables export GDK_SCALE=2 export GDK_DPI_SCALE=0.5 Gnome/GTK can as well be scaled globally with this Gnome setting gsettings set org.gnome.desktop.interface text-scaling-factor 2.0 Chromium, can be scaled with the following command chromium --high-dpi-support=1 --force-device-scale-factor=1.5 Xpra (python) can be used along with Run scaled to achieve a per app scaling. Environment variables modification can be placed in ~/.profile for a global and automatic appliance after login. Scaling the desktop with Xorg X11 Xorg's extension RandR have a scaling feature and can be configured with xrandr. This can be used to scale the desktop to display a bigger environment, this can be useful for HiDPI (High Dots Per Inch) displays. RandR can also be used the other way around, example making a screen with 1366x768 max resolution support a greater resolution like 1920x1080. This is achieved by simulating the new greater resolution while rendering it for the supported max resolution, similar to when we watch a Full-HD video on a screen that is not Full-HD. Scaling the desktop without changing the resolution Getting the screen name: xrandr | grep connected | grep -v disconnected | awk '{print $1}' Reduce the screen size by 20% (zoom-in) xrandr --output screen-name --scale 0.8x0.8 Increase the screen size by 20% (zoom-out) xrandr --output screen-name --scale 1.2x1.2 Reset xrandr changes xrandr --output screen-name --scale 1x1 Scaling the desktop and simulate/render a new resolution When using xrandr to "zoom-in" with the previous method, the desktop remain full screen but when we "zoom-out" with for instance xrandr --output screen-name --scale 1.2x1.2 (to get an unsupported resolution) the desktop is not displayed in full screen because this require updating the resolution (to probably a higher unsupported resolution by the screen), we can use a combinaison of --mode, --panning and --scale, xrandr's parameters to achieve a full screen "zoom-out" scaling (simulate a new resolution), example: Get the current setup xdpyinfo | grep -B 2 resolution # or xdpyinfo Configuration example Scaling at: 120% Used/max screen resolution: 1366 x 768 Resolution at 120% (res x 1.2): 1640 x 922 (round) Scaling factor (new res / res): 1.20058565 x 1.20208604 The idea here is to increase the screen resolution virtually (because we are limited to 1366x768 physically) the command would be (replace screen-name): xrandr --output screen-name --mode 1366x768 --panning 1640x922 --scale 1.20058565x1.20208604 Reset the changes with xrandr --output screen-name --mode 1366x768 --panning 1366x768 --scale 1x1 # restarting the desktop may be required example with KDE # kquitapp5 plasmashell # plasmashell & Making xrandr changes persistent There is a multitude of methods to make xrandr changes persistent, this and this QA have many examples. Experiments notes As a side note and experiments result while using SDDM + KDE, and after many tests to achieve a persistent config, I ended up loading a script with ~/.config/autostart (systemsettings5 > Startup... > Autostart), and naming my script 00-scriptname to make it run first. # 00-scriptname # Applying the main xrandr suited changes (scaling at x1.15) xrandr --output eDP1 --mode 1366x768 --panning 1574x886 --scale 1.15226939x1.15364583 # This is where it get odd/complicated, sometimes the screen resolution is not applied correctly or not applied at all... # Note that "xrandr --fb" can be used alone to change the screen resolution on a normal situation... # Here we will be taking advantage of xrandr's "--fb" feature to make the config appliance stable and works every-time. # The odd thing here is while re-applying the new resolution 1574x886 with "--fb" nothing happen, but # if we use use an unsupported resolution like 1574x884 (vs 1574x886) then xrandr force the resolution # to "reset itself" to the configured resolution (1574x886)... # In short just re-apply the setting with "--fb" and an unsupported resolution to force a reset. # ("--fb" can be used alone here without re-applying everything) #xrandr --fb 1574x884 xrandr --fb 1574x884 --output eDP1 --mode 1366x768 --panning 1574x886 --scale 1.15226939x1.15364583 References Some KDE's gui tools: systemsettings5 > display, kcmshell5 xserver and kinfocenter. Links and sources: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 and 12.
How to scale the resolution/display of the desktop and/or applications?
1,337,145,221,000
I can change the name of a window with Ctrl-a Shift-a. Instead of editing several window names by hand, is there a way to have them automatically named after the current directory?
Make your shell change the window title every time it changes directory, or every time it displays a prompt. For your ~/.bashrc: if [[ "$TERM" == screen* ]]; then screen_set_window_title () { local HPWD="$PWD" case $HPWD in $HOME) HPWD="~";; $HOME/*) HPWD="~${HPWD#$HOME}";; esac printf '\ek%s\e\\' "$HPWD" } PROMPT_COMMAND="screen_set_window_title; $PROMPT_COMMAND" fi Or for your ~/.zshrc (for zsh users): precmd () { local tmp='%~' local HPWD=${(%)tmp} if [[ $TERM == screen* ]]; then printf '\ek%s\e\\' $HPWD fi } For more information, look up under Dynamic titles in the Screen manual, or under “Titles (naming windows)” in the man page.
GNU Screen: new window name change
1,337,145,221,000
I'm curious about the security of leaving a root shell running inside a detached screen session. I typically never do this. Aside from the potential of my non-root user account being compromised (password exposed, ssh key compromised, etc), are there other vectors of entry into a detached, password-protected screen session I should be worried about, or can a detached screen session be considered inert?
I think it is a security issue, because that "Aside from the potential of my non-root user account being compromised" can be rather large. But there are other increased risks beyond that. For example, you've now opened yourself up to a theoretical exploit which allows one to change permissions in the screen socket dir (/var/run/screen on my system, but sometimes /tmp is used). That exploit now has an path to getting root, which it might not otherwise. sudo has other advantages, if you can train yourself to use it for each command rather than doing sudo su -. It logs actions (which, unless you're logging remotely, doesn't meaningfully increase security, but does give you a trail of what you've done). And it helps prevent accidents by requiring intentional escalation for each command, rather than switching to an entirely-privileged session.
Is it secure to leave a root shell running in detached screen session?
1,337,145,221,000
Every time I log into a VM with root, su into a user account, and try to use screen it throws an error: Cannot open your terminal '/dev/pts/0' - please check. A Stack Overflow post said I needed to use script /dev/null to fix it, and it works, but it still doesn't explain why I need to type script /dev/null. I would like to understand what it does and why I need to type it.
You cannot open /dev/pts/0 because it's owned by root, and after you su-ed into another user you're no longer able to open it via its path, but you're still able to use it via the opened handle to it, which was inherited from the parent process. script /dev/null will create another pty, owned by the current user. Anyways, that bug/limitation seems to have been fixed in recent versions of screen (eg. 4.99.0), which will correctly send the handle to the current terminal via the SCM_RIGHTS ancillary message on a unix domain socket, instead of sending just the name of the terminal and have the screen server try to open it (and fail). Same thing with tmux.
What does 'script /dev/null' do?
1,337,145,221,000
When I need to open different processes or terminals that I need to check, I just open a new tab in my terminal and use different workspaces in my machine to keep everything organized. I do some web development, using a Linux machine. I've seen that a lot of people use screen to accomplish what I'm doing, but I can't see any advantage. In fact, I thought it would be worse since now I have to remember all states in screen instead of having some terminals in a workspace named "terminals". What am I missing? How do you actually use screen?
I use screen both locally and remotely. I find that I use screen because it gives me the ability to Run multiple tasks without making multiple ssh connections to a remote server, Run a long-running task in screen, detach, disconnect. The job will still be running in screen and I can come back later, reattach, and check its progress. Have a more or less persistent workspace on a server, which is nice when I am doing something that involves multiple steps over the course of a day. Receive important system information in a non-intrusive way using the screen profile customizations provided by byobu. Use "Named Tabs": In screen I can give each "tab" in screen a name, allowing me to instantly know where to switch to. Use more keyboard shortcuts. If you do most of your work at the computer, not having to use the mouse is a real plus. I find that screen's keyboard shortcuts provide a bit more power, but this may just because I've never invested in truly learning all of the GTK shortcuts. Here is a screen shot of a recently started screen session using byobu and other customizations:
Is screen useful?
1,337,145,221,000
Suppose I have an attached screen, but I forgot to execute screen -L initially. Is it possible to enable and disable the logging of the currently attached screen without re-executing screen? I know that it's possible to take what is essentially a screenshot of a currently attached screen by pressing Ctrl+a h (that key combo followed by h), but I want to enable persistent logging of the attached screen. Is it possible?
To enable logging on the current window of a screen session, press Ctrl+AH (uppercase H, Shift+H if you prefer). That actually toggles the logging state (so if the windows was being logged beforehand, it is now no longer logged). That's the log command in screen, so you can also do Ctrl+A: and enter log (or log on to turn it on instead of toggling the state), or run screen -X log on within the shell running in the current window. To enable logging on all windows, use the at command to apply that to all windows: screen -X at '#' log on Or press, Ctrl+A: and enter at \# log on. For more details, see: info -f screen --index-search=at info -f screen --index-search=log
GNU Screen: How to enable or disable logging while screen is already attached?
1,337,145,221,000
I'm looking at tmux from screen, and have hit a bump while configuring the (highly configurable!) tmux key bindings. Problem is, in my .screenrc I have bindkey ^[[d prev bindkey ^[[c next bindkey ^[[a title bindkey ^[[b screen 1 and the bindings work (they originally came from rxvt-tabbedex). But in tmux there's apparently no way to bind commands to ShiftLeft/Right combinations. Please prove me wrong.
Try this (as a partial example): bind -n S-Right next-window bind -n S-Left previous-window That should be enough to make it easy to get the other 2 settings working too. It works on my tmux installation (1.4) but YMMV. You can also use the meta key (option on Macs, alt on PCs): bind-key -n M-Right next-window bind-key -n M-Left previous-window If you're using Terminal.app in OS X you need to enable the use of the option key in the Preferences for that to work. (As far as I remember it works by default in iTerm, but if not it can definitely be enabled.)
How do I bind to Shift+{Left,Right} in tmux?
1,337,145,221,000
I am using bash and GNU screen on centos7. I notice that if I ssh to another server, change the title (via ctrl+a+A), and log out of the server that my new title gets overwritten by USER@HOST:~. How can I stop it from doing this? I've looked into dynamic titles and determined that's what's at play, but I'm unsure of how to disable that feature...
As documented in the man page, screen looks for a null title-escape-sequence. bash sends this sequence via the PROMPT_COMMAND environment variable (for example, mine defaults to printf "\033k%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}". To disable this feature for a particular window, I just run unset PROMPT_COMMAND from that window. Of course, one could just add this to their ~/.bashrc or to a specific environment file to make it more persistent.
How do I stop screen from clobbering my titles?
1,337,145,221,000
I use screen as my window manager through putty. Screen has been great, but I need a way to increase my buffer when I run commands. I have no buffer when I scroll up, no std out is saved beyond my window size on any terminal. How can I increase this I can't seem to find an option in the commands? Ctrl + a ? doesn't seem to have what I am looking for.
Do Ctrl + a : then enter scrollback 1234 sets your buffer to 1234 lines. You enter scrollback mode ("copy mode") with Ctrl + a Esc, then move in vi-style, leave copy mode with another Esc
Increase buffer size while running screen
1,337,145,221,000
So let's say you boot up your Linux install all the way to the desktop. You start up a gnome-terminal/konsole/whatever so you have a tty to enter commands to. Now let's say I SSH into that same machine. It will bind me to another tty to enter commands to. Now let's say I want to "switch" my tty from my original SSH one to the gnome-terminal one started earlier. Basically I'm asking if there is any way to do the same thing screen -x does but without screen? I know you can easily send output to the other tty simply by echoing something into the /dev file, but I don't know a way to 'view' what's in the tty. Any ideas?
Maybe these schema can clarify the situation. This is the usual setting: Terminal (/dev/ttyX or /dev/pts/x) device | (screen)<--[<output]----x-------(stdout) Process1 Terminal (keyboard)---[input >]---o-\----->(stdin) \ \ (hardware console or \ `----(stdout) Process2 virtual console or terminal `---->(stdin) emulators like xterm, …) And there is no way to plug some new Process3 like this: Terminal device | (screen)<---o---[<output]--x------(stdout) Process1 Terminal (keyboard)---/-x--[input >]-o-\---->(stdin) | / \ \ | | \ `---(stdout) Process2 | | `--->(stdin) | | \ `---------------------(stdout) Process3 `--------------------->(stdin) What screen (and others) does is allocating some pseudo terminal device (like xterm does) and redirect it to one or more "real" terminals (physical, virtual, or emulated): Terminal pseudo devices ,--> Terminal (/dev/pts/x) | _______/ device Terminal <--[<output]--- | | | 1 ---[input >]--> |screen | <--[<output]---x-----(stdout) Process1 |Process| ---[input >]--o-\--->(stdin) Terminal <--[<output]--- | | \ \ 2 ---[input >]--> |_______| \ `--(stdout) Process2 `-->(stdin) Using screen -x you can attach one more terminal, xterm, whatever (say Terminal 3) to the screen session. So no, you can't communicate directly through stdin/stdout with processes attached to a different terminal. You can only do so through the process that is controlling this terminal if it happens to be a pseudo terminal, and if this process was concieved to do so (like screen is).
How can I switch between ttys without using screen?
1,337,145,221,000
I'm using screen on debian lenny, and I would like to use the -R option. From man screen: -R attempts to resume the youngest (in terms of creation time) detached screen session it finds. If successful, all other com‐ mand-line options are ignored. If no detached session exists, starts a new session using the specified options, just as if -R had not been specified. However, when I run screen -R it does not actually attach to the youngest detached session. Instead, it complains that there are "several suitable screens" and that I need to choose one of them. Am I missing something? How do I make this work as advertised?
Try using screen -RR. Example: $ screen -ls There are screens on: 5958.pts-3.sys01 (08/26/2010 11:40:43 PM) (Detached) 5850.pts-1.sys01 (08/26/2010 11:40:35 PM) (Detached) 2 Sockets in /var/run/screen/S-sdn. Note that screen 5958 is the youngest. Using screen -RR connects to screen 5958. The -RR options is somewhat further explained in the documentation for -d -RR. -d -RR Reattach a session and if necessary detach or create it. Use the first session if more than one session is available. Another trick I often use is to use -S to give the screen a tag/label. Then you can reattach using that tag without having to remember what was happening in each screen if the list gets unwieldy. Example (Launch screens for vim and curl): $ screen -dm -S curl $ screen -dm -S vim $ screen -list There are screens on: 11292.vim (08/27/2010 12:02:53 AM) (Detached) 11273.curl (08/27/2010 12:01:42 AM) (Detached) Note: The -dm option was just used to start a detached screen And then, at a later date, you can easily reconnect using the tag curl. # screen -R curl
How to make screen -R attach to the youngest detached session?
1,337,145,221,000
Is it possible to change the parent process of a process? If yes, how? For example, how does screen manage to attach a screen session and the processes running inside it to different shell processes? Is there change of parent process? I seem to heard of other ways of change of shell process in which a program is running, but I don't remember. Is there also change of parent process of the program? I thought disown on a process changes the parent process of the process, simply because the name disown implies that. But I found it is not true. Emacs client can attach to emacs server on a different terminal tab. Is there change of parent process?
The parent process id (ppid) of a process cannot be changed outside of the kernel; there is no setppid system call. The kernel will only change the ppid to (pid) 1 after the processes parent has terminated - if the process did not respond to a signal that the parent was terminated. For this to happen, the process needs to have ignored various signals (SIGHUP, SIGTERM, etc.) beforehand. screen(1) has a very elegant means of handling detaching and reattaching. When you first start screen, you are actually starting a user interface (ui), which by default will create a daemon (the session manager). This daemon has no terminal associated with it, a new process group (setpgrp(2)), a new session id (setsid(2)). The daemon, running as SCREEN, will then create subprocesses connected to pseudo-terminals (pty), then multiplexes the data from the ptys and the ui (screen). The subprocesses think they are talking with a real terminal. If the ui screen terminates, the daemon SCREEN will still be running, buffering data, handling signals, waiting for a new ui, etc. because it is a different process group and in its own session. When you reattach with a new ui screen, then the daemon will continue to multiplex as it was doing before. The daemon will run continue running until all subprocesses terminate, is killed, a fatal bug is encountered or the host reboots.
Change the parent process of a process?
1,337,145,221,000
Is there a way to present the GNU Screen session name and window title in the prompt of the shell (let us say, the Bash prompt defined by PS1)?
Screen supplies some environment variables (from screen(1) manpage): STY Alternate socket name. WINDOW Window number of a window (at creation time). The "at creation time" means that if you renumber a window (using screen's number command), the shell will not be told about the change and $WINDOW will still be the same as the first window number. You could use something like: PS1='\u@\h(${STY}:${WINDOW}):\w$ '
Showing GNU screen session name and window title in shell prompt
1,337,145,221,000
My scenario is this: I have a screen session running in a remote location. Inside this screen is a consoled-based program. When run without screen, this program starts in the terminal and accepts commands on its standard input. What I want is a way to remotely send a command to screen so that this command is received by the console program. Maybe like this: My PC -> SSH Send Msg Auto -> Screen Session -> Program (Run command received) So from a remote PC I can send via SSH commands to the screen which sends them to the program. The program accepts them and executes them.
If I understand correctly, you want to send input to a program running inside a screen session. You can do this with screen's stuff command. Use screen's -X option to execute a command in a screen session without attaching to it. screen -S sessionname -p windowname -X stuff 'command1 command2 ' If you want to see the program's output, see the hardcopy, log and logfile commands.
Sending input to a screen session from outside
1,337,145,221,000
I'm working with emacs (on the terminal) and I use screen to switch between terminals. The key combination Ctrl+A is grabbed by screen. Is there a way to change screen key binding?
Sure, you can change the binding in either Screen or Emacs. I use Ctrl+\ in Screen, which is used by very few applications. It's used in the terminal to send the QUIT signal — a stronger version of Ctrl+C, which fewer applications catch and may produce a core dump. That's rarely useful, and if you need it you can press Ctrl+\ \. A bigger argument against Ctrl+\ is that it's hard to type on some keyboard layouts. Anyway, pick the key you prefer. To change the Screen escape key, use the escape directive in ~/.screenrc: escape ^\\\ In Emacs, C-a normally moves to the beginning of the line; you can use Home instead. C-x C-a is not bound. That leaves modes with custom bindings for C-a or C-x C-a or C-c C-a. If you choose C-\, it's normally bound to toggle-input-method, which is useful if you write in multiple languages and useless otherwise. You can rebind it to a different key with global-set-key in your ~/.emacs: ;; overrides a binding for `suspend-frame', which is also bound on `C-x C-z' (global-set-key "\C-z" toggle-input-method)
Working with screen and emacs
1,337,145,221,000
When I search a terminal window in tmux, it sets the cursor the keyword search, but doesn't highlight the matching word. Screen used to do this, and it was much easier to visually find a match. Thanks!
According to the developer1, this isn't currently possible in tmux. [1] http://sourceforge.net/mailarchive/message.php?msg_id=27427973
How do I highlight a search result in tmux?
1,337,145,221,000
I have several long-running GNU screen sessions. I ssh to the box they're running on and run screen -d -r foo to detach them if they're connected anywhere else, and then attach them in my current window. 99% of the time this works fine, but on occasion I get this: $ screen -d -r foo [2430.foo detached.] ...and nothing happens; I can't get back to the shell at all. Trying in another window does the same thing, the only thing I can do is destroy that screen session (losing all the programs that were running in it) and recreate it Why does this happen? How can I avoid it or reconnect successfully when it does happen? Edit: My .screenrc: startup_message off defwritelock off bind q quit caption always '%{gk} (%n) %t %{y}%d %M %Y :: %c:%s %{b}%W%{d}' screen -t ZSH autodetach on shelltitle ZSH defutf8 on Edit: The end of an strace log when trying to attach: readlink("/proc/self/fd/0", "/dev/pts/14", 4095) = 11 stat64("/dev/pts/14", {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 14), ...}) = 0 stat64("/dev/pts/14", {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 14), ...}) = 0 geteuid32() = 1000 getegid32() = 1000 open("/dev/pts/14", O_RDWR|O_NONBLOCK) = 3 geteuid32() = 1000 getegid32() = 1000 close(3) = 0 ioctl(0, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400 opost isig icanon echo ...}) = 0 umask(0) = 022 lstat64("/var/run/screen", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0 access("/var/run/screen/S-mrozekma", F_OK) = 0 stat64("/var/run/screen/S-mrozekma", {st_mode=S_IFDIR|0700, st_size=4096, ...}) = 0 umask(022) = 0 uname({sys="Linux", node="etudes-2", ...}) = 0 rt_sigaction(SIGHUP, {0x806e520, [], 0}, {SIG_DFL, [], 0}, 8) = 0 geteuid32() = 1000 getegid32() = 1000 open("/var/run/screen/S-mrozekma", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = 3 getdents(3, /* 6 entries */, 32768) = 124 stat64("/var/run/screen/S-mrozekma/2386.chat", {st_mode=S_IFIFO|0700, st_size=0, ...}) = 0 geteuid32() = 1000 getegid32() = 1000 open("/var/run/screen/S-mrozekma/2386.chat", O_WRONLY|O_NONBLOCK) = 4 geteuid32() = 1000 getegid32() = 1000 fcntl64(4, F_SETFL, O_RDONLY) = 0 geteuid32() = 1000 getegid32() = 1000 getdents(3, /* 0 entries */, 32768) = 0 close(3) = 0 geteuid32() = 1000 getegid32() = 1000 setuid32(1000) = 0 setgid32(1000) = 0 stat64("/var/run/screen/S-mrozekma/2386.chat", {st_mode=S_IFIFO|0700, st_size=0, ...}) = 0 getpid() = 30081 write(4, "\0gsm\4\0\0\0/dev/pts/14\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 12336
Not sure if I had the same issue as you, but sometimes I've the similar screen behaviour every time I network was accidentaly disconnected. After a while ( about 10-15 minutes ) screen is available again for reconnection. After some invetigations, I've found a small note in the man page: nonblock [on|off|numsecs] Tell screen how to deal with user interfaces (displays) that cease to accept output. This can happen if a user presses ^S or a TCP/modem con‐ nection gets cut but no hangup is received. If nonblock is off (this is the default) screen waits until the display restarts to accept the out‐ put. If nonblock is on, screen waits until the timeout is reached (on is treated as 1s). If the display still doesn't receive characters, screen will consider it "blocked" and stop sending characters to it. If at some time it restarts to accept characters, screen will unblock the display and redisplay the updated window contents. May be it'll help somebody, cause this is the only page about screen freezes after disconnetion google gave me.
GNU screen freezes trying to reattach
1,337,145,221,000
I login as root and can not see the screen created by other others using screen -ls. I think the root user could have way to access those screen, but I can't find useful options of screen: Use: screen [-opts] [cmd [args]] or: screen -r [host.tty] Options: -4 Use IPv4. -6 Use IPv6. -a Force all capabilities into each window's termcap. -A -[r|R] Adapt all windows to the new display width & height. -c file Read configuration file instead of '.screenrc'. -d (-r) Detach the elsewhere running screen (and reattach here). -dmS name Start as daemon: Screen session in detached mode. -D (-r) Detach and logout remote (and reattach here). -D -RR Do whatever is needed to get a screen session. -e xy Change command characters. -f Flow control on, -fn = off, -fa = auto. -h lines Set the size of the scrollback history buffer. -i Interrupt output sooner when flow control is on. -l Login mode on (update /var/run/utmp), -ln = off. -list or -ls. Do nothing, just list our SockDir. -L Turn on output logging. -m ignore $STY variable, do create a new screen session. -O Choose optimal output rather than exact vt100 emulation. -p window Preselect the named window if it exists. -q Quiet startup. Exits with non-zero return code if unsuccessful. -r Reattach to a detached screen process. -R Reattach if possible, otherwise start a new session. -s shell Shell to execute rather than $SHELL. -S sockname Name this session <pid>.sockname instead of <pid>.<tty>.<host>. -t title Set title. (window's name). -T term Use term as $TERM for windows, rather than "screen". -U Tell screen to use UTF-8 encoding. -v Print "Screen version 4.00.03 (FAU) 23-Oct-06". -wipe Do nothing, just clean up SockDir. -x Attach to a not detached screen. (Multi display mode). -X Execute <cmd> as a screen command in the specified session. So which should I use?
Unless the screen session in question is created with multiuser on, you can't. Even if you set your SCREENDIR variable to point at the other user's socket directory, screen will just complain that you don't own the directory and quit when you try to use it. Of course, you can simply su to the other user and use screen in the normal way.
How to access screen created by other users?
1,337,145,221,000
I often leave tasks running within screen so that I can check on them later, but I sometimes need to check which command is running within the screen. It's usually a php script of sorts, such as screen -d -m nice -n -10 php -f convertThread.php start=10000 I don't record which screens are running which command, but I'd like to be able to get a feel for the progress made by checking what command was run within it, without killing the process. I don't see any option for this within the screen help pages.
I recently had to do this. On Stack Overflow I answered how to find the PID of the process running in screen. Once you have the PID you can use ps to get the command. Here is the contents of that answer with some additional content to address your situation: You can get the PID of the screen sessions here like so: $ screen -ls There are screens on: 1934.foo_Server (01/25/15 15:26:01) (Detached) 1876.foo_Webserver (01/25/15 15:25:37) (Detached) 1814.foo_Monitor (01/25/15 15:25:13) (Detached) 3 Sockets in /var/run/screen/S-ubuntu. Let us suppose that you want the PID of the program running in Bash in the foo_Monitor screen session. Use the PID of the foo_Monitor screen session to get the PID of the bash session running in it by searching PPIDs (Parent PID) for the known PID: $ ps -el | grep 1814 | grep bash F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 0 S 1000 1815 1814 0 80 0 - 5520 wait pts/1 00:00:00 bash Now get just the PID of the bash session: $ ps -el | grep 1814 | grep bash | awk '{print $4}' 1815 Now we want the process with that PID. Just nest the commands, and this time use the -v flag on grep bash to get the process that is not bash: $ echo $(ps -el | grep $(ps -el | grep 1814 | grep bash | awk '{print $4}') | grep -v bash | awk '{print $4}') 23869 We can use that PID to find the command (Look at the end of the second line): $ ps u -p 23869 USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND dotanco+ 18345 12.1 20.1 5258484 3307860 ? Sl Feb02 1147:09 /usr/lib/foo Put it all together: $ ps u -p $(ps -el | grep $(ps -el | grep SCREEN_SESSION_PID | grep bash | awk '{print $4}') | grep -v bash | awk '{print $4}')
Find out which command is running within a screen session
1,337,145,221,000
I'm trying to make an ssh connection (via lsh) from one Ubuntu host to another from within screen. If I try to run mc right after that I get the following error: Unknown terminal: screen-256color-s Check the TERM environment variable. Also make sure that the terminal is defined in the terminfo database. Alternatively, set the TERMCAP environment variable to the desired termcap entry. The question is - who's causing this failure? Is it local host? remote? some package missing (which?), something not done by lsh-server? or client? Just to be clear - I don't want workarounds like "TERM=xterm mc", I want to be able to use visual themes which support 256 colors on the (remote) console.
Finally, I've managed to figure out "obvious" package which supply screen-256-color-s (got to be installed on remote machine): sudo apt install ncurses-term fixed the problem for me: nice 256 colors and no need for ugly workarounds with environment variables. Hooray! :)
ssh from screen leads to unknown terminal error
1,337,145,221,000
I would like to know if there is a way to get tmux to behave like screen -D -R so I could say, have the command as a default command in Putty. These screen switches would force detach of an existing screen session for my user (even if it was still active and logged-in somewhere else) and reattach it to the current session. Also, in the case that no screen session existed, it would create a new one. I like tmux and can see clear benefits over screen, but the existence of this feature would really seal the deal. tmux attach doesn't seem to create a new session if there isn't one. The man page for tmux says: If no server is started, attach-session (attach) will attempt to start it; this will fail unless sessions are created in the configuration file. What does the section in bold mean? (I can't find an example of creating a session in the conf file).
Yes: tmux attach -d || tmux new. -d is necessary to behave like screen -D, ie, detach everybody else. Connect by ssh, then attach or create could be something like: $ cat bin/stmux #!/bin/sh exec ssh -t "$@" 'tmux attach -d || tmux new' $ stmux my.remote.box
Is there a tmux equivalent of "screen -D -R"
1,337,145,221,000
I am looking for suggestions for a setup for my particular needs. I haven't done much linux since college and want to get back into it as a hobby. I have some not-too-powerful hardware (512 MB ram, single core). I want to do everything via text-based shells and editors, such as vim. My goal is to never touch the mouse. I need the ability to have multiple shells open at once, one running a web server, one running vim, one running my application build pipeline, another one for ad-hoc shell commands such as wget, grepping and untarring, etc. I need to be able to open new shells and switch between shells quickly with the keyboard. But even though I want multiple shells, I do not want a graphical desktop environment. I don't ever want to be tempted to use the mouse; part of my purpose is to force myself to learn the command-line way of doing various tasks. I also want to be able to take advantage of my large monitor, running vim with a couple hundred columns dipslayed. Is this possible?
I read through your questions several times before I realized that I definitely have a recommendation for you: vim with tmux: http://tmux.sourceforge.net/ tmux is a screen 'multiplexor' that lets you have several windows and panes 'within 1' It is a successor to the venerable 'screen' program, long a staple of many cli coders. One of its original winning features over vim was the ability to do split windows vertically as well as horizontally. However screen has moved forward and can now do that too. Example: Another part of the setup that I would recommend is a good set of aliases. These will make your typing and interaction a lot easier and quicker Some of my favorites are shown here as examples: alias gcv='git commit' alias gg='git grep ' # for searching (add parameter) alias gst='git status -sb' # I must use this 100 times a day!!! alias h='history | tail' alias hg='history | grep' # for searching my history (add parameter) alias l='ls -alFtrG' alias ls='ls --color=auto' alias mv='mv -i' alias p='pwd'# at least 200 times a day! so 2 chrs saved * 200 = 400 less characters to type ;) Aliases can be setup in a .bash_aliases file that is called from .bashrc with: # Alias definitions. if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi Chances are you already have that code, so just your own .bash_aliases file. Both these options work on a Mac and that is an important consideration for myself (a mostly Ubuntu user). Most folks using tmux remap the keys to make it easier. The default bindings are just not that good. Here are my settings: $ cat ~/tmux.conf # mdd tmux settings bind r source-file ~/.tmux.conf \; display "Reloaded!" # Reload with ctrl-r set -g prefix C-a # prefix from ctrl-b to ctrl-a unbind C-b # allow ctrl-b for other things set -sg escape-time 1 # quicker responses bind C-a send-prefix # Pass on ctrl-a for other apps set -g base-index 1 # Numbering of windows setw -g pane-base-index 1 # Numbering of Panes # bind | split-window -h # Split panes horizontal bind \ split-window -h # Split panes horizontal bind - split-window -v # Split panes vertically bind h select-pane -L # Switch to Pane Left bind j select-pane -D # Switch to Pane Down bind k select-pane -U # Switch to Pane Up bind l select-pane -R # Switch to Pane Right bind -r C-h select-window -t :- # Quick Pane Selection bind -r C-l select-window -t :+ # Quick Pane Selection bind -r H resize-pane -L 5 # Switch to Pane Left bind -r J resize-pane -D 5 # Switch to Pane Down bind -r K resize-pane -U 5 # Switch to Pane Up bind -r L resize-pane -R 5 # Switch to Pane Right setw -g mode-mouse off # Mouse Off set -g mouse-select-pane off # Mouse Off set -g mouse-resize-pane off # Mouse Off set -g mouse-select-window off # Mouse Off #set -g default-terminal "screen-256color" setw -g monitor-activity on # Activity Alerts set -g visual-activity on set -g status-fg white # Status line Colors set -g status-bg black setw -g window-status-fg cyan # Window list color setw -g window-status-bg default setw -g window-status-attr dim setw -g window-status-current-fg white # Active Window Color setw -g window-status-current-bg red setw -g window-status-current-attr bright set -g pane-border-fg green # Pane colors set -g pane-border-bg black set -g pane-active-border-fg white set -g pane-active-border-bg yellow set -g message-fg white # Command/Message Line. set -g message-bg black set -g message-attr bright set -g status-left-length 40 # Status Line, left side set -g status-left "#[fg=white]Session: #S #[fg=yellow]#I #[fg=cyan]#P" set -g status-utf8 on # Status Line, right side set -g status-right "-------" set -g status-interval 60 # frequency of status line updates set -g status-justify centre # center window list setw -g mode-keys vi # vi keys to move unbind v # Open panes in same directory as tmux-panes script unbind n bind v send-keys " ~/tmux-panes -h" C-m bind n send-keys " ~/tmux-panes -v" C-m unbind Up # Maximizing and Minimizing... bind Up new-window -d -n tmp \; swap-pane -s tmp.1 \; select-window -t tmp unbind Down bind Down last-window \; swap-pane -s tmp.1 \; kill-window -t tmp bind P pipe-pane -o "cat >>~/#W.log" \; display "Toggled logging to ~/#W.log" # Make keys for copy mode be like vi unbind [ bind Escape copy-mode unbind p bind p paste-buffer bind -t vi-copy 'v' begin-selection bind -t vi-copy 'y' copy-selection Finally (to close the loop), here's my .vimrc settings themselves that I like having to make the shell easier to use: " mdd specific stuff --- start set hlsearch set incsearch set number " more3 mdd stuff - set tabs to be spaces and length of 2 characters. set smartindent set tabstop=2 set shiftwidth=2 set expandtab " mdd specific stuff --- end " " Forget being compatible with good ol' vi set nocompatible " Get that filetype stuff happening filetype on filetype plugin on filetype indent on " Turn on that syntax highlighting syntax on " Why is this not a default set hidden " Don't update the display while executing macros set lazyredraw " At least let yourself know what mode you're in set showmode " Enable enhanced command-line completion. Presumes you have compiled " with +wildmenu. See :help 'wildmenu' set wildmenu " Let's make it easy to edit this file (mnemonic for the key sequence is " 'e'dit 'v'imrc) nmap <silent> ,ev :e $MYVIMRC<cr> " And to source this file as well (mnemonic for the key sequence is " 's'ource 'v'imrc) nmap <silent> ,sv :so $MYVIMRC<cr> highlight ExtraWhitespace ctermbg=red guibg=red match ExtraWhitespace /\s\+$/ autocmd BufWinEnter * match ExtraWhitespace /\s\+$/ autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/ autocmd InsertLeave * match ExtraWhitespace /\s\+$/ autocmd BufWinLeave * call clearmatches() Finally I make a few changes to my .bashrc file For example with shopt -s autocd when I type a directory name (that exists) my shell cd's into that directory immediately. Nifty! So here's my .bashrc changes: # Automatic cd'ing shopt -s autocd # Have cd show directory info ('cos my shell doesn't show full directory path in $PS1 prompt (intended). cd() { builtin cd "$@" && pwd } # enable programmable completion features if [ -f /etc/bash_completion ] && ! shopt -oq posix; then . /etc/bash_completion fi PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* # mdd Terminal Multiplexor 6/15/2012 if [[ ! $TERM =~ screen ]]; then exec tmux fi [ -z "$TMUX" ] && export TERM=xterm-256color export EDITOR=vim git config --global --add color.ui true
Suggested setup for an ultra-lightweight text-based programming environment in linux
1,337,145,221,000
When working at a normal xterm (not sure about a "real" terminal), when a full-screen program such as man or vim is closed, it disappears, leaving your screen so you can see your prompt, and previous prompts including where you launched the program that closed. When I am running within GNU Screen, however, when the program is closed it does not clear but is simply shifted up so a prompt can be displayed. To me this is ugly, and I'd like to know if "normal" behaviour can be resumed. I realise I could manually clear the screen myself but a) I don't want to and b) that would result in a totally clear screen, not what I'm after (though perhaps better, if this is as good as it gets).
Some terminals, such as xterm, support what is known as an “alternate screen”: there are separate screens for full-screen programs and for scrolling programs. In xterm, you can switch between the two screens with the “show alternate screen” command at the bottom of the Ctrl+mouse 2 menu. This behavior is disabled by default in screen but can be enabled with the altscreen option: add altscreen on to your ~/.screenrc.
Clearing GNU Screen after full-screen application
1,337,145,221,000
Is there any way to make GNU Screen not close if I end all its subprocesses? Ideally, it would create a new window running a shell if I accidentally closed the last window.
Assuming you're using bash and accidentally closes the shell with Ctrl-D, you can export IGNOREEOF=1 This will give you a warning and require you to press Ctrl-D twice, or type exit instead.
Prevent GNU Screen from closing
1,337,145,221,000
I'm using screen (the problematically named terminal session manager) on a remote system accessed over SSH - to run long running processes and such. I have eventually started using a command to attach directly to the screen session, instead of first logging in through SSH and then start screen: ssh -t hostname screen -xRR The use of the -xRR is to attach to the existing screen session, if available, otherwise just create a new one. The problem is that when a new session is created, it is not created as a login shell: $ shopt -q login_shell; echo $? 1 and as a result, login session setup (running .profile and friends) isn't done and then parts of the setup is missing, compared to first using SSH to login and then running screen - in which case the shell SSH starts is a login shell and it is setup properly and screen I guess inherits the environment. I tried using the -l flag on screen, which is documented as "Login mode", but it doesn't help - I think it only updates the "login time" for things like who. Any idea how to get screen to run a login shell?
From the man pages of GNU screen: -s program sets the default shell to the program specified, instead of the value in the environment variable $SHELL (or "/bin/sh" if not defined). This can also be defined through the "shell" .screenrc command. ... shell command Set the command to be used to create a new shell. This overrides the value of the environment variable $SHELL. This is useful if you’d like to run a tty-enhancer which is expecting to execute the program specified in $SHELL. If the command begins with a ‘-’ character, the shell will be started as a login-shell. Typical shells do only minimal initialization when not started as a login-shell. E.g. Bash will not read your ~/.bashrc unless it is a login-shell. defshell is currently a synonym to the shell .screenrc command. So you have two options: Run the following command to ensure that bash is launched as a login shell: ssh -t hostname screen -xRR -s -bash If you want this behavior to be the default one, add the following line to your $HOME/.screenrc file on the destination host (or wherever you run your screen command): shell -bash
Running GNU screen through SSH, the shell is not a login shell?
1,337,145,221,000
I've been searching to find a way to send a command to a detached screen session. So far, so good. This is what I've come up with: $ screen -S test -p 0 -X stuff 'command\n' This command works as it should. But, I would like the output from it too, echoed straight in front of my eyes (no need for a .log file or something, I just want the output). Using the screen -L command, is not an option.
Use a first in first out pipe: mkfifo /tmp/test Use a redirect operator. Redirect command's output to /tmp/test for example like this: screen -S test -p 0 -X stuff 'command >/tmp/test\n' Then in another shell tail -f /tmp/test. Note you may also want to redirect error messages using the 2>&1 operator. Example As requested in the comments, let's assume we have a php script accepting user input and printing the server load on the input of "status": # cat test.php <?php $fp=fopen("php://stdin","r"); while($line=stream_get_line($fp,65535,"\n")) { if ($line=="status") {echo "load is stub";} } fclose($fp); ?> You create two fifos: # mkfifo /tmp/fifoin /tmp/fifoout You call a screen: screen In another console, let's call it console 2 you find out the name of your screen: # screen -ls There is a screen on: 8023.pts-3.tweedleburg (Attached) 1 Socket in /var/run/screens/S-root. In console 2 you send the command to the screen: # screen -S 8023.pts-3.tweedleburg -p 0 -X stuff 'php test.php </tmp/fifoin >/tmp/fifoout\n' you see the command appearing in the screen. Now in console 2 you can send commands to your php process: echo "status" >/tmp/fifoin and read from it: # cat /tmp/fifoout load is stub
Send command to detached screen and get the output
1,337,145,221,000
My current screen session has 12 open windows on it. It's been running for weeks... I know I executed an ImageMagick convert command in one of these 12 screen windows sometime last week... is there any way I can easily search through the Bash history of all 12 instances, without closing them or running history | grep convert in all 12 screens?
You can run history -a; history -c in all windows to save the history. And then history -r to refresh it. To solve it more permanently add this to your .bashrc: export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
Can I easily search my history across many screen windows?
1,337,145,221,000
I would like to create a bash script to automatically open a screen window with 4 sessions running predetermined commands. I'd like to open htop and slurm on the top two frames, squidview in the middle large frame and a blank terminal on the bottom large frame. Is this possible to set up with a single bash script?
This does something like you desire: $ cat my_screenrc screen top split focus down screen vmstat 1 split focus down screen focus bottom $ screen -c my_screenrc screen appears to be more directed toward screen flipping than multiple panels and the documentation is pretty arcane.
Opening multiple split windows with GNU screen with single bash script
1,337,145,221,000
I ssh-connect an ubuntu server from an ubuntu client machine. And resume my screen session by running screen -d -r name. I'm not able to scroll inside the screen session. I created my screen session by running screen -S name. Do I have to pass any extra flag to make the scrolling work?
By default Screen will keep a scrollback buffer, but you can't use it the same way as the "conventional" scrollback buffer maintained by your terminal emulator. I.e. you can't use your mouse to scroll up. You need use screen key bindings to enable copy/scrollback mode. For me that is with CTRL+a ESC (screen will notify that copy mode has been enabled) and then I can use the UP-arrow on my keyboard to scroll back, but you can also use the other movement keybindings to move and select in the scrollback buffer.
How to scroll inside a screen session of an ssh connection?
1,337,145,221,000
Running screen I see this: How can I start screen directly, without this welcome screen?
Add startup_message off to your .screenrc: startup_message on|off Select whether you want to see the copyright notice during startup. Default is `on', as you probably noticed. Actually, the default is to display the startup message only when screen is not passed any argument.
Starting screen without welcome screen
1,337,145,221,000
I'd like to configure SSH and screen such that a login will always reattach to a screen session. Ideally, that session would not quit but detach when I press C-d. How can this be achieved? And what other useful settings are there to make my SSH-life easier?
I just did the following for all of my servers so that when I connect via SSH I am automatically put into a Screen session. Add the following to the ~/.bashrc for your user accounts: # Auto-screen invocation. see: http://taint.org/wk/RemoteLoginAutoScreen # if we're coming from a remote SSH connection, in an interactive session # then automatically put us into a screen(1) session. Only try once # -- if $STARTED_SCREEN is set, don't try it again, to avoid looping # if screen fails for some reason. if [ "$PS1" != "" -a "${STARTED_SCREEN:-x}" = x -a "${SSH_TTY:-x}" != x ] then STARTED_SCREEN=1 ; export STARTED_SCREEN screen -RR -S main || echo "Screen failed! continuing with normal bash startup" fi # [end of auto-screen snippet] This will start a screen session named main if it doesn't exist or reconnect to it if it does. This was done because I have several other screen sessions running detached for various services and didn't want to connect to them.
How to effectively use screen and SSH?
1,337,145,221,000
I am trying to download a file with wget but in background and inside a screen that detaches ... My initial command was: wget http://www.example.com/file.zip -O temp/file.zip; mv temp/file.zip downloads/file.zip; That would nicely move file once downloaded, preventing me from handling downloads/ files while they still download in background. Now I need to run that in backgorund with screen, so I run and detach it: screen -dm wget http://www.example.com/file.zip -O temp/file.zip; But how can I still pass the move command and so that it runs when first one is completed ? Edit: I tried quotes based on DopeGhoti's answer: screen -dm 'wget http://mirror.leaseweb.com/speedtest/100mb.bin -O 1.bin; mv 1.bin 2.bin' cannot identify account 'wget http:'. and this: screen 'wget http://mirror.leaseweb.com/speedtest/100mb.bin -O 1.bin; mv 1.bin 2.bin' cannot exec 'wget http://mirror[...] no such file or directory Edit: I tried with full /usr/bin/wget and /usr/bin/mv paths, it complains about missing session name, I gave it session name with -S foo, now it exits silently, no such screen to resume and no files downloaded: screen -dm -S foo '/usr/bin/wget http://mirror.leaseweb.com/speedtest/100mb.bin -O 1.bin; /usr/bin/mv 1.bin 2.bin'
It works if I specify bash -c screen -dm bash -c 'command1; command2;' User meuh provided this solution in comments, thanks.
run two commands in screen detached
1,337,145,221,000
I just learned about screen and it looks wonderful. Some questions: How do they actually work? Why are downloads / process not interrupted in screens even though something bad happened?
Very briefly (it's possible to write several pages on the topic): screen works by setting up a server process that takes over all input/output directly to your terminal, starting client processes for each window that you create, and connecting the server and clients as they are started using a pseudo-terminal connection (a feature of the operating system). Once a client (window) is created, it is isolated from the other clients. It communicates via the pseudo-terminal connection to the server process, which updates the terminal. The server keeps track of what should be shown on the terminal in a given window, providing you with the ability to switch between windows. The clients run without knowing if screen is currently displaying their information.
How does `screen` actually work?
1,337,145,221,000
I'm using a recent version of GNU Screen, supporting vertical splits. Once I have split a window in 2, how can I switch so that they are both dividing the whole region in half horizontally versus vertical? I need to change to horizontal in order to copy some text with mouse from one window without the visual selection overflowing and grabbing text from the other window. Then I would need to switch back again to a vertical split from horizontal.
GNU screen doesn't come with any layouts predefined, so you need to roll your own. Here is what I've added to my ~/.screenrc : # define layouts layout new 'horizontal' split layout new 'vertical' split -v layout new 'main' # bind control sequences for new layouts bind V layout select 'vertical' bind H layout select 'horizontal' bind ' ' layout next # <- actually means Ctrl-a + Space With this it's possible to switch layouts with Ctrl+a Space | V | H. (Actually, all control sequences start with Ctrl+a by default, so I'll omit it from now on.) This solution is not ideal - after starting a screen session you initially have to tediously focus on each 'region' (parts of a layout) with TAB, and attach a process (man screen of all places insists on calling them 'windows' ) with n|p|0-9|Ctrl+c or a different method of your choice. I imagine you'll want to detach instead of killing when possible. ... and this should hopefully cover your use case. Cheers!
GNU Screen switch from vertical split to horizontal and back
1,337,145,221,000
Is there a way I can open a new 'screen' session on my RHEL box as a non-root user? When I try to open a new screen using the 'screen' command as a non-root user, it fails and I get the following message: Cannot open your terminal '/dev/pts/2' - please check. I researched a little bit and found people suggesting to change the permissions on /dev/pts to grant the non-root user (who is trying to open the screen) a read/write access. Though it may work, it does not look like a neat solution. Is there a 'legal' way that allows a non-root user to open a screen session? Edited : I have this issue on my RHEL 5.5, 6.2 and 6.5 machines. The screen version on all these boxes are 'Screen version 4.00.03 (FAU) 23-Oct-06'. P.S:- I know that I can open a screen session as root and 'su' to start my command/process, but that is not what I am looking for.
This is a known problem, if you ssh as root somewhere and then su to become a normal user: $ ssh root@server # su -l anthon $ screen Cannot open your terminal '/dev/pts/3' - please check. It is e.g. described in these posts from 2005 The solution is to directly login as the user you want the screen session to run as.
How can I start a 'screen' session as non-root user
1,337,145,221,000
I have a Python script test.py that only contains: print('hi'). I want to run it in a screen so that the output of the screen is saved by script. I use the following command to run test.py in a screen, it works fine: screen -dm bash -c 'python test.py' However, I haven't managed yet to find a way to use script to save the output of the screen. How can I do it? I unsuccessfully tried: script -c "screen -dm bash -c 'python test.py'" output.txt: the output file output.txt doesn't contain hi, but only: Script started on Fri 26 Aug 2016 01:04:59 PM EDT Script done on Fri 26 Aug 2016 01:04:59 PM EDT I use Ubuntu 14.04.4 LTS x64. Documentation: https://www.gnu.org/software/screen/manual/screen.html: -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. http://linux.about.com/library/cmd/blcmdl1_sh.htm : -c string: If the -c option is present, then commands are read from string. If there are arguments after the string, they are assigned to the positional parameters, starting with $0. script's man page: -c, --command run command rather than interactive shell
You should do it the other way round, run script inside screen: screen -dm bash -c 'script -c "python test.py" output.txt'
How can I save the output of a detached screen with script?
1,337,145,221,000
When running a bash script, I would like to be able to tell if it is running within a screen. Is this possible? I want this so that .bashrc can set the colour of the command prompt depending on whether the sessions is started within a screen or not. Discovered this link once mine was answered: How can I tell whether I'm in a screen?
Typically, $STY will be set. So: if [ -n "$STY" ]; then echo "I'm most likely running under screen" fi $STY is typically what you need to talk to your screen. That is used to construct the path of the Unix domain socket used to control screen (something like /var/run/screen/S-$USER/$STY. Now, that won't work for instance if from that screen, you ssh to another machine. The shell started there won't have $STY in its environment, and that wouldn't be of any use to it anyway, since it wouldn't be able to access the Unix domain sockets on your machine. However, it is possible to query the terminal with an escape sequence to determine its type: if [ -t 1 ] && [ -t 0 ]; then s=$(stty -g) stty -icanon -echo min 0 time 3 printf '\033[>c' type=$(dd count=1 2> /dev/null) stty "$s" case $type in (*'>83;'*) echo "this is screen" esac fi Another approach, as suggested by @val0x00ff is to check the value of the $TERM environment variable. That value is meant to tell applications what type of terminal they're talking to. It is set by screen to something that starts with screen (as screen can implement different variants of terminals). $TERM is passed accross rlogin, rsh, telnet, ssh. It's not as guaranteed to work as the above but is simpler and less intrusive. case $TERM in (screen*) echo "I'm more than likely running in screen" esac Like for the previous solution, you may be running in screen, but you may not be able to issue commands to it with screen -X for instance. However note, that you can pass commands using escape sequences (though it's not enabled by default for security reasons).
How to tell if terminal session is running within screen
1,337,145,221,000
I have had a GNU screen session running for days. I find myself in the situation that I need to save the terminal contents (which I can scroll up to see) into a file. Is this possible? I estimate it to be below 5000 lines. I found a way to set up screen to log future output to a file. But in this case, I need to also save past output (or as much of it as is present).
You can use hardcopy -h command to save the contents of the current scroll buffer to a file. As described in man screen: hardcopy [-h] [file] Writes out the currently displayed image to the file file, or, if no filename is specified, to hardcopy.n in the default directory, where n is the number of the current window. This either appends or overwrites the file if it exists. See below. If the option -h is specified, dump also the contents of the scrollback buffer. You said: I estimate it to be below 5000 lines. 5000 lines is really a lot. The default length of scroll buffer in screen is just 100, not ~5000 lines. Unless you started your screen session with a larger scroll buffer setting it will not be possible to retrieve all ~5000 lines of the scroll buffer.
Save past GNU screen output to a file
1,337,145,221,000
I want to start a program with SSH using PHP, which works fine, but now I want to kill the screen with PHP, but the only thing I know is the name of the screen. How do I find out the screen ID (automatically)?
You can use the environment variable $STY to determine whether you're in a screen session and also what the name of the session is that you're inside. Example Initially we're sitting in a terminal window, not inside of a screen session. $ echo $STY $ Spin up a screen session: $ screen -ls There is a screen on: 31543.tscrn (Detached) 1 Socket in /var/run/screen/S-saml. Connect to it: $ screen -r 31543.tscrn Inside screen session: $ echo $STY 31543.tscrn $ Killing a session With the name of the session you can kill it using screen. $ screen -X -S tscrn kill You can also use the number there too. $ screen -X -S 31543 kill Confirm that its been killed: $ screen -ls No Sockets found in /var/run/screen/S-saml.
Find out screen id
1,337,145,221,000
I have to run some scripts in a screen and I used the C-a H command to record the output to a screenlog.0 file when I press the shortcut keys the message is Logfile "screenlog.O" closed. But if I try to find it with locate screenlog.0 it doesn't show up. Where can I find the screenlog.0 file?
You can find the screenlog.0 file in screen's current working directory (cwd). This is either the directory that was the cwd when you started screen, or it's a directory you subsequently changed to using the :chdir screen command. The easiest way to find out what this directory is is to open a new window with a shell in it using Ctrl-a c and check the pwd of the new shell (which is usually visible straight away in the prompt).
Where can I find the screenlog.0 file?
1,337,145,221,000
I am running an interactive curses program in a screen session on quite weak hardware. Most of the time, the screen is detached. Is there a way for this program to detect this situation, and basically stop painting on the screen?
There's an irssi script called screen_away that sets your away status based on whether or not the screen is attached. It works like this: Every shell running within a screen will have the STY environment variable set to the socket name. You can run screen -ls to get the path where all the sockets are stored: $ screen -ls There are screens on: 11824.pts-24.mmrozek (Attached) 2306.ssh (Detached) 6615.chat (Attached) 3 Sockets in /var/run/screen/S-mmrozek. Check the execute bit on /var/run/screen/.../$STY. If it's set, the screen is attached; otherwise it's detached. You can see from the output above that two of my three screens are attached, and here the corresponding execute bits are set: $ ls -l /var/run/screen/S-mmrozek/ total 0 prwx------ 1 mmrozek mmrozek 0 Oct 5 13:04 11824.pts-24.mmrozek prw------- 1 mmrozek mmrozek 0 Sep 23 23:45 2306.ssh prwx------ 1 mmrozek mmrozek 0 Oct 5 12:43 6615.chat You could also just keep checking the output of screen -ls for a row that contains $STY, and see if it ends in (Attached) or (Detached), but that requires running screen over and over
Can a program detect it is running in a detached screen?
1,381,981,716,000
I want to know if it is possible to make emacs, when running in a gnu screen or tmux session, use the same colors as when TERM=xterm. In a gnu screen or tmux session, TERM=screen and emacs uses a different set of colors as compared to when TERM=xterm. For example, when TERM=xterm-256color, the foreground color of font-lock-comment-face is 'Firebrick'. But when TERM=screen-256color, it is set to 'chocolate1'. For tmux to work properly, the TERM variable must be set to screen or some derivative, so resetting TERM is not an option for me.
The definition of font-lock-comment-face includes many variants for cases of varying color support. The chocolate1 variant is used when there are at least 88 colors available and the “background” is “dark”. The Firebrick variant is used when there are at least 88 colors available and the “background” is “light”. The difference is caused by some code that gives special meaning to TERM values that start with xterm, rxvt, dtterm, and eterm: it considers them to have a “light” background. You should be able to customize frame-background-mode* to its light value to always use the “light” color variants. If your Emacs is not new enough to have its own term/screen.el, then you will also need to adapt one for yourself that makes the appropriate color-adjusting calls. You might use the one from Emacs trunk, or I have a Gist that includes a .emacs.d/lisp/term/screen.el (with some extra bits to recognize the modifier+arrows/Home/End sequences provided by tmux’s xterm-keys option), and the .emacs modification needed to let it automatically load. Of course, there could still be other bits of code that directly check the TERM value and do something different for screen- and xterm-like values… * M-x customize-variable frame-background-mode
emacs colors based on $TERM environment variable
1,381,981,716,000
I use the screen Screen visual consoles. To detach a screen I need to press Ctrl+A followed by D but some time a session is closed without detaching it. It appears as (Attached) on screen -list: eduard@eduard-X:~$ screen -list There are screens on: 4561.pts-46.eduard-X (30.03.2015 14:48:51) (Attached) 4547.pts-46.eduard-X (30.03.2015 14:48:33) (Detached) 4329.pts-41.eduard-X (30.03.2015 14:46:28) (Attached) 3995.pts-30.eduard-X (30.03.2015 14:30:01) (Detached) If i try to restore it, screen responds that there is no screen to resume: eduard@eduard-X:~$ screen -r 4329 There is a screen on: 4329.pts-41.eduard-X (30.03.2015 14:46:28) (Attached) There is no screen to be resumed matching 4329. Can I still resume a screen that I did not detached properly?
Sure, with screen -d -r You can choose which screen to detach and reattach as usual by finding the pid (or complete name) with screen -list. screen -d -r 12345
How can I resume a screen that I did not manage to detach?
1,381,981,716,000
When I use screen I can only see the current data on the terminal (commands, messages, etc.). Is there a way, apart from printing anything I want to a file, to see the previous messages (the same way a normal terminal emulator would)?
Hitting Ctrl+A then Esc should get you into a special mode to look through the scroll-back buffer much like hitting Esc in vim gets you into a mode where you can navigate the file rather than inserting into it. If your scroll-back buffer doesn't have enough lines in it to be useful you can change this in your ~/.screenrc file: defscrollback 10000 Once in the scroolback buffer, you can use common key bindings like J/K/H/L, PgUp/PgDown, G/Shift+G, ^/$ and arrows to navigate. You can use Space to set a mark. Setting a second mark will copy everything between the two marks to the screen clipboard which you can then paste into any window using Ctrl+A ]. You can also search and do other things with the buffer. See the screen users manual for more.
Is there a way to show previous messages in screen?
1,381,981,716,000
By default, the title of a screen session is the name of the last command entered, which is fine for me, but in some cases I'd like to change it. I know the command Ctrl-A A, but it only changes the title until the next command, and I'd like it to stay there until I decide otherwise. EDIT: Here's the preexec function I found in my .zshrc if [[ "$TERM" == "screen" ]]; then local CMD=${1[(wr)^(*=*|sudo|-*)]} echo -n "\ek$CMD\e\\" fi
Depends how things are set up, but by default, something like this should work. settitle() { printf "\033k$1\033\\" } Then run: settitle NEWTITLE. See screen title docs and GNU screen faq for more details. Given Ctrl+A A is only changing it until the next command, it's probably being set by $PS1 (all shells), or $PROMPT_COMMAND/DEBUG trap (bash only) or precmd/preexec (zsh only). You should look for any place that \e or \033 appears with k or \\ after it, basically like my settitle example above. UPDATE You said you had a custom preexec. Why not change it to this: if [[ "$TERM" == "screen" ]]; then local CMD=${1[(wr)^(*=*|sudo|-*)]} echo -n "\ek${TITLE:-$CMD}\e\\" fi Then you can set a custom title by running: TITLE="my title" and unset the title by running TITLE= Don't forget to change precmd and $PS1 as well if necessary. ASIDE You could even extend this to all terminals (e.g. xterm, gnome-terminal, etc.) by not hard coding the \ek and \e\\. This is how I do it: terminit() { # determine the window title escape sequences case "$TERM" in aixterm|dtterm|putty|rxvt|xterm*) titlestart='\033]0;' titlefinish='\007' ;; cygwin) titlestart='\033];' titlefinish='\007' ;; konsole) titlestart='\033]30;' titlefinish='\007' ;; screen*) # status line #titlestart='\033_' #titlefinish='\033\' # window title titlestart='\033k' titlefinish='\033\' ;; *) if type tput >/dev/null 2>&1 then if tput longname >/dev/null 2>&1 then titlestart="$(tput tsl)" titlefinish="$(tput fsl)" fi else titlestart='' titlefinish='' fi ;; esac } # or put it inside a case $- in *i* guard if test -t 0; then terminit fi # set the xterm/screen/etc. title settitle() { test -z "${titlestart}" && return 0 printf "${titlestart}$*${titlefinish}" } Then you can change your preexec to: if [[ "$TERM" == "screen" ]]; then local CMD=${1[(wr)^(*=*|sudo|-*)]} settitle "${TITLE:-$CMD}" fi
Force title on GNU screen
1,381,981,716,000
I use GNU screen a lot with zsh as my shell. It would be a nice feature (I think) to be able to display the current directory name (not the full path) as the tab title. I can do that with CTRL+A SHIFT+A but that is manual. I would like it to change whenever I change directory. Does anyone know of a way to do this? Edit: The answer also feature the solution for bash.
For zsh: Put this in your ~/.zsh [centos@centos ~]$ cat .zsh if [[ ${TERM} == "screen-bce" || ${TERM} == "screen" ]]; then precmd () { print -Pn "\033k\033\134\033k%m[%1d]\033\134" } preexec () { print -Pn "\033k\033\134\033k%m[$1]\033\134" } else precmd () { print -Pn "\e]0;%n@%m: %~\a" } preexec () { print -Pn "\e]0;%n@%m: $1\a" } fi PS1=$'%{\e[0;32m%}%m%{\e[0m%}:%~> ' export PS1 [centos@centos ~]$ In your ~/.screenrc hardstatus string "%h" caption always "%{= kw} %-w%{= wk}%n*%t%{-}%+w%{= kw} %=%d %M %0c %{g}%H%{-}"
Screen status bar to display current directory for zsh/bash shell
1,381,981,716,000
In vim, there's a CtrlV to do block selection. How can I do it in screen?
Assuming you already know how to use Space to do normal selection in screen's copy mode, the only new keys you need are c to set the left margin, and C to set the right margin. This is described in the screen manual.
How to do block selection in `screen`
1,381,981,716,000
Using the screen terminal environment, I ofen enter copy mode by using Ctrl-aEsc. However, the scrollable output is often too short for me to view the desired information. What do I modify to extend the length of this output?
It's all there on the screen man page: You can do it from the command line when you start screen: -h num Specifies the history scrollback buffer to be num lines high. Or from the .screenrc file: defscrollback num Same as the scrollback command except that the default setting for new windows is changed. Initial setting is 100. Or from within screen, using the C-a: command: scrollback num Set the size of the scrollback buffer for the current windows to num lines. The default scrollback is 100 lines. See also the "defscrollback" command and use "C-a i" to view the current setting.
Extend the scrollable content of gnu-screen?
1,381,981,716,000
In a script I am building I'm experimenting with how to automate as much as possible. One of the more interesting challenges is to connect to a byobu screen session and execute a command. So I started in the obvious place, looking on how many screen sessions there are (game has 3 windows in byobu and lordquackstar has 2. The users are in separate putty instances) game@quackgame:~$ screen -ls There is a screen on: 2019.byobu (01/05/2011 05:10:04 PM) (Attached) 1 Socket in /var/run/screen/S-game. Only one there, so I checked for the system lordquackstar@quackgame:/home/game$ sudo ls -lAR /var/run/screen/ /var/run/screen/: total 0 drwx------ 2 game users 100 2011-01-06 09:18 S-game drwx------ 2 lordquackstar lordquackstar 100 2011-01-06 09:17 S-lordquackstar /var/run/screen/S-game: total 4 prwx------ 1 game users 0 2011-01-08 07:55 2019.byobu -rw------- 1 game users 0 2011-01-06 09:18 byobu-exchange -rw-r--r-- 1 game users 3 2011-01-08 07:32 byobu.updates-available /var/run/screen/S-lordquackstar: total 4 prwx------ 1 lordquackstar lordquackstar 0 2011-01-08 07:42 1169.byobu -rw------- 1 lordquackstar lordquackstar 0 2011-01-06 09:17 byobu-exchange -rw-r--r-- 1 lordquackstar lordquackstar 3 2011-01-08 07:35 byobu.updates-available Still no multiple screens So for my question: How can I connect to a window in byobu from a script? On a slightly related note, once I connect to it from a bash script, is there any way to send it a command then detatch?
You can directly attach to a previously detached byobu/screen session including the window: byobu -r -p2 will reattach into window 2 (or a named one). -X can send any command to a byobu/screen session and also works with the -p switch. byobu -p2 -X stuff "uname -a $(echo -ne '\r')" This will send a uname -a to the second (third actually) byobu window, the echo at the end sends a carriage return so the commands gets executed.
Connect to byobu screen session and execute command?
1,381,981,716,000
I noticed a difference in 'env' before and after a 'screen' call, is there any additional clarity on what gets called (for setting environment variables)? I couldn't see any clear explanation from a quick search on 'man screen' Some googled queries on the topic: http://alan.lamielle.net/2009/03/09/environment-variables-and-gnu-screen https://superuser.com/questions/105954/updating-screen-session-environment-variables-to-reflect-new-graphical-login I guess a more specific sub-question would be, what is not instantiated in a screen session vs. that of a normal log-in?
A process inherits the environment variables from the parent, this means the first time you call screen (create a new one) it has a copy of all the environment variables of the parent process. Now screen adjusts/creates some variables like COLUMNS, LINES, TERM, TERMCAP, WINDOW and STY. You can also adjust or delete environment variables in your screenrc with setenv/unsetenv. On some systems, screen is setuid or setgid in order to update utmp and wtmp; then a few more variables are removed from the environment when screen starts, such as LD_LIBRARY_PATH. If you attach to an existing screen session your environment variables won't be copied as the screen process already exists and has it own environment variables (from the time when you started the process before). This means your changed environment variables won't be visible in the processes started by screen as they are copied from the parent process which has the old environment variables.
How does 'screen' impact environment variables?
1,381,981,716,000
For a while now I've been using Byobu to manage screen sessions for me. However I've run into a strange issue: The session keeps locking. By locking I mean that I can't type anything, and only if I wait a few minuites does unlock and do everything I typed in before. Currently its getting worse. The session keeps locking every minute or so. Even when I've restarted Putty, switched from Private Key auth to password auth, and even changed Putty installations, it still freezes. Its gotten to the point where I'll login and the current window is frozen but I'm able to switch to another window, only for that to freeze in a few seconds. Another new development is that sometimes when I first login Byobu won't even come up, it will just sit there after the "Last login" line. One time I got a WriteMessage: Broken pipe error and it dropped to normal shell without byobu. Strangely the tunnel's I've opened up still work. I was able to check the CPU graphs and saw that the server wasn't under any load, meaning that the session didn't freeze because it had other things to do. Any suggestions on how to fix this?
Try this, it worked for me on putty: Ctrl+Q - XON Ctrl+S - XOFF
Byobu/screen constantly freezes in Putty
1,381,981,716,000
I have a systemctl service that starts a process smd-loop in a screen session. This process requires acces to remote SSH sources (for syncing purposes) and thus needs to be able to access my id_dsa private key. How can I set up the systemd service so that it will work? The following service starts the process correctly but requires me to attach to the screen session and manually type in the id_dsa password. [Unit] Description=smd loop After=local-fs.target network.target [Service] User=%i Group=users Type=Forking ExecStart=/usr/bin/screen -S smd-loop-win -md "smd-loop" RemainAfterExit=yes When I manually start smd-loop the id_dsa password is not required since I've insalled the pam_ssh module which starts an ssh-agent that holds the password at login.
You need to put the identity files containing not encrypted private key into ~/.ssh directory of the user the service is running. Also, you need to set the HOME environment variable for it, for example if it is run as root: ExecStart=/usr/bin/env HOME=/root /usr/bin/screen -S smd-loop-win -md "smd-loop" Alternatively, if you have a control on how smd-loop invokes ssh you may add -I option to tell the ssh an identity file to use. In any case the identity file has to be owned by this user and has to be accessible by this user only (chmod 0400 ~/.ssh/id*) .
systemd service that needs .ssh/id_dsa password
1,381,981,716,000
Today I finally decided to reinstall OS on my home server from CentOS 5 to CentOS 7. Along with that, I decided to try tmux instead of screen that I was using for ages. I was able to reconfigure its look&feel almost perfectly for my needs but there is still one annoying thing. In screen, when I do some actions (for example in vi - trying to move cursor up while on first line, or press unknown hotkey, etc.) - background blinks for a moment - I suppose this is kind of warning or something like that. Anyway, I like this feature. Now in tmux, it doesn't blink. More than that, it plays system default sound. This is really annoying. How do I change this sound to visual blinking? I'm connecting to this server via putty from win desktop, if this matters.
short: in your .tmux.conf set -g visual-bell on long: Some applications check both the bel and flash terminal capabilities, and allow you to choose which will be used. tmux does not. It reads only bel, so you could modify your terminal description to change the bel to a string for flashing the display. That might work, except that while tmux reads terminfo data, it does not use the corresponding tputs or putp functions for sending terminfo data which includes time-delays. You need those delays on most terminals (including all of those imitating xterm) to implement flash. Interesting, the terminal description for screen has flash=\Eg, but neither it or tmux do anything with that (screen uses it internally as part of its visual-bell feature). tmux likewise has a visual-bell feature, which you can set in your configuration file. That will not blink the screen, but just put a momentary alert in the status line. Further reading: tmux — terminal multiplexer visual-bell [on | off] If this option is on, a message is shown on a bell instead of it being passed through to the terminal (which normally makes a sound). Also see the bell-action option. bell-action [any | none | current | other] Set action on window bell. any means a bell in any window linked to a session causes a bell in the current window of that session, none means all bells are ignored, current means only bells in windows other than the current window are ignored and other means bells in the current window are ignored but not those in other windows.
Blink tmux instead of sound
1,381,981,716,000
A process listening on port 8113 (Solr) is not responding. I've found its PID via netstat but the server has about two dozen Solr process running in various screen sessions. 3607.foobar-client2 (12/27/14 20:54:02) (Detached) 3797.solr.bo.app (12/25/14 11:51:30) (Detached) 2962.solr (12/25/14 11:47:23) (Detached) 1410.solrTester (12/25/14 11:39:41) (Detached) 1348.solrReports (12/25/14 11:38:41) (Detached) .... The only way that I've found to identify them involves stopping the processes. I tried identifying them by which files are open by lsof but that was not helpful at all in this circumstance. Is there any way to determine, based on PID, in which screen session a process is running?
Found it! To find the screen instance in which PID 351 is running, search the PID 351 environment for the string "STY=": $ grep -z '^STY=' /proc/351/environ STY=1410.neverFindMe Or using ps (if screen session names don't contain space characters): $ ps wwep 351 | grep -o 'STY=\S*' STY=1410.neverFindMe
Identify in which screen instance a process is running
1,381,981,716,000
I would like to use screen (from GNOME Terminal, via ssh) like I use GNOME Terminal without screen, or as close as possible to that. Specifically: In GNOME Terminal, I can scroll back using the mouse wheel, the scrollbar or Shift+PgUp/PgDn. In screen, I have to go to copy mode (Ctrl+A,[) to be able to scroll back (mouse wheel works after that). Scrolling behavior can be changed (see this answer and this answer) but this solution has the following flaws: When I open a file with less or vim, I can scroll above the editor 'window' with my mouse wheel and see the previous contents of the terminal. When I close the editor, its contents stay in the scrollback buffer (sometimes in several copies) instead of disappearing. This behavior can be changed using altscreen on (see this answer) but the only effect is that when the editor is closed, the old terminal contents are appended to the scrollback buffer in my terminal window so I can still see the editor crap when I scroll back using my mouse wheel. Does this mean it's not possible to have nice scrolling in screen? Basically, all I'd like is being able to scroll just like in copy mode (using the mouse wheel, and scrollbar if possible) but without having to enter copy mode.
Perhaps you cannot have what you are asking. From the terminal's standpoint: screen is a full-screen (no pun) application just like vi or less. the terminal implements scrolling and an alternate screen. when the terminal is in alternate-screen mode, it does not add to its scrollback area as it would in normal mode. in gnome-terminal (and perhaps some others — an option in xterm), the terminal will send up/down arrow keys to the application when it is in alternate-screen mode. when not in alternate screen mode, your terminal will scroll through the visible screen and the terminal's scrollback area without any notification to the application running inside it. From screen: screen does not know anything about mice or scrolling; it passes that information to the application running inside screen. screen simulates an alternate screen; it has no way to access the alternate screen of the terminal. you can disable the alternate screen feature of the terminal, as indicated in the question. In short, because screen does not have any way to access the scrollback of the terminal, your available choices are those that the terminal provides.
Make screen work like a terminal (scrolling + alternate screen) [duplicate]
1,381,981,716,000
I've set up a systemd service to run my Minecraft server. Now, I need it to repeat the start script when the server crashes. Here's my code so far: #!/bin/bash while true; do cd /home/mcserver/Spigot echo Starting Spigot... echo 600 > ./restart-info java -jar spigot.jar echo Server has stopped or crashed, starting again in 5 minutes... sleep 300 done I can actually view the output of spigot.jar using systemctl status spigot, but I also want to control the server console, maybe using screen. When I try to do this: screen -S "Spigot" java -jar spigot.jar I'll get the Must be connected to a terminal error. This command only works in a terminal (not in a script) and I can attach it using screen -r. Is there any way to "bypass" this screen bug? I already tried to place script /dev/null before the screen command. I don't want to use screen with -d and -m because it'll run in the background and the script will keep restarting my server.
I don't want to use screen with -d and -m because it'll run in the background and the script will keep restarting my server. So use -D instead of -d (note the capital case!) -D -m This also starts screen in "detached" mode, but doesn't fork a new process. The command exits if the session terminates. As screen won't fork a new process, it will block while java is running, and exit when the server stops. As a bonus, if you add -S spigot you can monitor the output (and even send commands!) from any terminal by attaching to that screen And... since you're using a systemd service anyway (and you should indeed), why are you doing this restart loop in your script? Let systemd handle that for you using Restart=always and RestartSec=5min
How to control systemd service using screen?
1,381,981,716,000
Sometimes my script bugs out and multiple screen sessions with the same name get created. Is there a way to kill all of these with this name in one command? Rx:/scripts# screen -S haydoz-script -X quit There are several suitable screens on: 13372.haydoz-script (09/10/11 07:44:05) (Detached) 12287.haydoz-script (09/10/11 07:30:45) (Detached) 12230.haydoz-script (09/10/11 07:17:42) (Detached) 7824.haydoz-script (09/09/11 11:42:26) (Detached) 7764.haydoz-script (09/09/11 11:35:40) (Detached) 15753.haydoz-script (09/04/11 15:00:27) (Detached) 15744.haydoz-script (09/04/11 15:00:26) (Detached) There are other screens running besides these ones that I do not want to kill.
If there are no other screen sessions running you can use the "hard" way and just kill them with killall screen. If you want to be nice you can iterate over your list of screen sessions and kill them one after another: # screen -S foo && screen -S foo [detached] [detached] # screen -ls There are screens on: 8350.foo (Detached) 8292.foo (Detached) 2 Sockets in /tmp/screens/S-joschi. # This is the interesting line. Just replace "foo" with the name of your session(s) # for session in $(screen -ls | grep -o '[0-9]*\.foo'); do screen -S "${session}" -X quit; done # screen -ls No Sockets found in /tmp/screens/S-joschi.
Killing multiple GNU screen sessions with the same name
1,381,981,716,000
I'd like to do a one line bash command that automatically does this: screen -S myserver python myserver.py # inside the new screen CTRL A, D (detach) I think this won't work: screen -S myserver && python myserver.py because python myserver.py won't be started inside the screen.
You can detach right after starting a program inside of screen: screen -dmS myserver python myserver.py From screen's man page -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.
Create a screen, launch a command in it and detach
1,381,981,716,000
I have a few long running commands that I would like to run together in the same screen (same tab in the terminal app). My current setup is like this: tmux new-session -d 'cmd1' tmux split-window 'cmd2' tmux split-window 'cmd3' tmux attach However, it seems that tmux split-window actually splits the last split, so if I run several command this way, the first command gets half the screen, and the other commands get progressively smaller and smaller parts. Is there a simpler way that runs all commands in equal-sized splits?
Just add the following command before your tmux attach tmux select-layout even-vertical
Running several commands in a screen-split
1,381,981,716,000
tmux and screen let you run different processes (e.g. vim, a bash script, mysql, psql, etc) in different virtual windows. But traditional Unix job control (using CTRL-z, fg, bg, and jobs) seem to give you some of the same functionality. Are there any advantages of multitasking using traditional job control over the newer ways via tmux and screen?
Suppose you've just started a program outside screen. Suddenly you realize you wanted to do something else in that terminal. Ctrl+Z. Screen and tmux introduce a layer of isolation between the application and the terminal. This isn't always a good thing. For example, I find their scrollback a lot less convenient than xterm's, so I rarely use screen unless I intend to (be able to) connect to that session remotely. If you've set up environment variables, a current directory and other parameters in a shell (which may be in a screen window), carrying those settings over to a new screen window can be a lot of work. It's convenient to be able to run several programs in that terminal. Sometimes you want to run a program in the background and have nothing to to with it any more: nohup program & disown %-. If you have a GUI application that occasionally misbehaves, it can be convenient to start it from a terminal and fg; Ctrl+C or kill %1 it if needed. Screen and tmux may not be installed.
What are the virtues of multitasking with traditional job control vs Tmux/Screen?
1,381,981,716,000
I'm trying to figure out how to make a script that will be able to send commands to a screen that will execute within whatever the screen is doing. Is this possible, and if so, how is it done? I've already tried screen -X etc, and it is not executing the commands.
Well it depends on the commands you need to execute: If you need to execute commands in an existing screen session, you need to re-attach and execute the commands using this command line: screen -r -S "<screenName>" "command/or/script/to/execute" If want to execute the commands inside of a new screen session, you can use this: screen -A -m -d -S "<screenName>" "command/or/script/to/execute" You can read more about some common screen commands here: 10 Screen Command Examples to Manage Linux Terminals
Linux - Sending a command to a screen through a shell script? [duplicate]
1,381,981,716,000
Why does tmux report $TERM=screen-256color Normally kitty reports $TERM=xterm-kitty Which should I use if I run tmux inside kitty? Obviously kitty provides advanced functionality and that makes sense that it reports xterm-kitty. Why does screen report that it's screen-256 are there programs that need to be aware that they're running in screen? Would it be problematic to call screen running in kitty xterm-kitty?
Which should I use if I run tmux inside kitty? When running tmux then you must use TERM=screen, TERM=tmux, or one of the derivatives e.g. TERM=screen-256color or TERM=tmux-256color. man tmux(1) states ... The TERM environment variable must be set to “screen” for all programs running inside tmux. New windows will automatically have “TERM=screen” added to their environment, but care must be taken not to reset this in shell start-up files. .. and further down clarifies ... Set the default terminal for new windows created in this session - the default value of the TERM environment variable. For tmux to work correctly, this must be set to ‘screen’ or a derivative of it. ... they also emphasize must. The tmux wiki continues with additional clarification and answers ... Inside tmux TERM must be "screen", "tmux" or similar (such as "tmux-256color"). Don't bother reporting problems where it isn't! Are there programs that need to be aware that they're running in screen? Yes. Many programs, such as tput, will not display correctly when they're running in screen (or tmux) unless they're using the correct TERM value. What is TERM and what does it do? The environment variable TERM tells applications the name of a terminal description to read from the terminfo(5) database. Each description consists of a number of named capabilities which tell applications what to send to control the terminal. For example, the "cup" capability contains the escape sequence used to move the cursor up. It is important that TERM points to the correct description for the terminal an application is running in - if it doesn't, applications may misbehave. The infocmp(1) command shows the contents of a terminal description and the tic(1) command builds and installs a description from a file (the -x flag is normally required with both). Would it be problematic to call screen running in kitty xterm-kitty? Not necessarily, as long as the TERM value in the running screen is set correctly (i.e. TERM=screen-256color) and there's valid terminfo strings for it that screen or tmux knows how to handle. Other derivatives (on my machine) are: /usr/share/terminfo/s/screen /usr/share/terminfo/s/screen-16color /usr/share/terminfo/s/screen-256color /usr/share/terminfo/s/screen.Eterm /usr/share/terminfo/s/screen.gnome /usr/share/terminfo/s/screen.konsole /usr/share/terminfo/s/screen.linux /usr/share/terminfo/s/screen.mlterm /usr/share/terminfo/s/screen.mrxvt /usr/share/terminfo/s/screen.rxvt /usr/share/terminfo/s/screen.teraterm /usr/share/terminfo/s/screen.vte /usr/share/terminfo/s/screen.xterm-r6 /usr/share/terminfo/s/screen.xterm-new /usr/share/terminfo/s/screen.xterm-xfree86 Once TERM is set, you could run infocmp. That will report if there's a valid terminfo for the value. Other tests can validate basic terminfo functionality, such as: for terminfos in $(find /usr/share/terminfo/s -type f -name 'screen*' -printf '%f\n' -o -name 'tmux*' -printf '%f\n'); do export TERM=$terminfos; printf "%s: %sthis is foreground color 10 %sitalics%s and now all attributes are turned off\n" "$terminfos" "$(tput setaf 10)" "$(tput sitm)" "$(tput sgr0)"; done
Screen and kitty what should $TERM be?
1,381,981,716,000
I need to determine if a file contains a certain regex at a certain line and to return true (exit 0) if found, and otherwise false. Maybe I'm overthinking this, but my attempts proved a tad unwieldy. I have a solution, but I'm looking for maybe others that I hadn't thought of. I could use perl, but I'm hoping to keep this "lightweight" as possible as it runs during a puppet execution cycle. The problem is common enough: in RHEL6, screen was packaged in a way that limited the terminal width to 80 characters, unless you un-comment the line at 132. This command checks to see if that line has already been fixed: awk 'NR==132 && /^#termcapinfo[[:space:]]*xterm Z0=/ {x=1;nextfile} END {exit 1-x}' /etc/screenrc Note: if the file has fewer that 132 lines, it must exit with false. I thought sed would be of help here, but apparently then you have to do weird tricks like null-substitutions and branches. Still, I'd like to see a sed solution just to learn. And maybe there is something else I overlooked. EDIT 1: Added nextfile to my awk solution EDIT 2: Benchmarks EDIT 3: Different host (idle). EDIT 4: mistakenly used Gile's awk time for optimized-per's run. EDIT 5: new bench Benchmarks First, note: wc -l /etc/screenrc is 216. 50k iterations when line not present, measured in wall-time: Null-op: 0.545s My original awk solution: 58.417 My edited awk solution (with nextfile): 58.364s Giles' awk solution: 57.578s Optimized perl solution 90.352s Doh! Sed 132{p;q}|grep -q ... solution: 61.259s Cuonglm's tail | head | grep -q : 70.418s Ouch! Don_chrissti's head -nX |head -n1|grep -q: 116.9s Brrrrp! Terdon's double-grep solution: 65.127s John1024's sed solution: 45.764s Thank you John and thank you sed! I am honestly surprised perl was on-par here. Perl loads in a bunch of shared libraries on startup, but as long as the OS is caching them all, it comes down to the parser and byte-coder. In the distant past (perl 5.2?) I found it was slower by 20%. Perl was slower as I originally expected but appeared to be better due to a copy/paste error on my part. Benchmarks Part 2 The biggest configuration file which has practical value is /etc/services. So I've re-run these benches for this file and where the line to be changed is 2/3rds in the file. Total lines is 1100, so I picked 7220 and modified the regex accordingly (so that in one case it fails, in another it succeeds; for the bench it always fails). John's sed solution: 121.4s Chrissti's {head;head}|grep solution: 138.341s Counglm's tail|head|grep solution: 77.948s My awk solution: 175.5s
With GNU sed: sed -n '132 {/^#termcapinfo[[:space:]]*xterm Z0=/q}; $q1' How it works 132 {/^#termcapinfo[[:space:]]*xterm Z0=/q} On line 132, check for the regex ^#termcapinfo[[:space:]]*xterm Z0=. If found quit, q, with the default exit code of 0. The rest of the file is skipped. $q1 If we reach the last line, $, then quit with exit code 1: q1. Efficiency Since it is not necessary to read past the 132nd line of the file, this version quits as soon as we reach the 132nd line or the end of the file, whichever occurs first: sed -n '132 {/^#termcapinfo[[:space:]]*xterm Z0=/q; q1}; $q1' Handling empty files The version above will return true for empty files. This is because, if the file empty, no commands are executed and the sed exits with the default exit code of 0. To avoid this: ! sed -n '132 {/^#termcapinfo[[:space:]]*xterm Z0=/q1; q}' Here, the sed command exits with code 0 unless the the desired string is found in which case it exits with code 1 The preceding ! tells the shell to invert this code to get back to the code we want. The ! modifier is supported by all POSIX shells. This version will work even for empty files. (Hat tip: G-Man)
awk or sed command to match regex at specific line, exit true if success, false otherwise
1,381,981,716,000
A former coworker configured screen for me and I just found out I could change this, but I don't know what the setting is supposed to be and the man page is a little vague. I've got this in my .screenrc # no annoying audible bell, please vbell on I don't have a vbell msg defined, but the man page says the default vbell msg is "Wuff Wuff", I've never seen that particular message. What I do see is a big annoying full screen flash every time I hit tab when a file doesn't exist (and this is starting to get on my nerves). It's better than a ding, but I'd rather have no indication than an annoying indication. So, is there any way to completely disable the vbell without defacto enabling the real bell? (Note, if you know this is just a putty question, I can close an ask on SuperUser, I saw the "bell" screen in the Putty setup which had some stuff that was already disabled for flashing - and it doesn't flash outside of screen)
You can do what you want in a terminal-independent way using just your .screenrc: vbell on vbell_msg '' termcapinfo * vb=: The settings are: first line (you already did this) second line cancels the Wuff, Wuff! third line sets the flash to an empty string Note that the trailing colon (:) is needed for the termcap syntax used by screen.
Preventing bell flash with screen in putty
1,381,981,716,000
I saw many place introduce screen to run background job stably even log out. They use screen -dmS name According to screen -h, this option means -dmS name Start as daemon: Screen session in detached mode. What is daemon? I don't understand. I found that if I simply type screen, I can enter automatically into a screen. After I run some command, and press Ctrl+a d, and then log off. The job is still running fine. So is this simple approach OK? Do I really need -dmS to make background job stable? Let me try to give a summary: Anything run in screen is safe to logging out (but you should detach the screen, not quit screen when you log out), no matter what the option you have set to screen. -dmS is just an option convienient for submitting jobs in background noniteractively. That is screen -dmS nameOfScreen command
You would only use -dm if you want to run a command in a screen session and not enter it interactively -S is just to give the session a usable name so you can reconnect to it again easily later If you want to use it interactively and don't want to give it a human readable name, you can omit all of those arguments safely. For example, if you just want to start up screen to run the command, say, /path/to/longTime and you don't want to watch it run you could do it either as screen -dmS longSession /path/to/longTime or you could do screen -S longSession $ /path/to/longTime ctrlad Both would accomplish the same thing, but one is both easier to script and a bit less typing.
Do I really need -dmS option in screen to run background job stably even log out?
1,381,981,716,000
My goal is to remote to a server through ssh, start a screen, start a script, let the script run, and exit the ssh session while keeping the screen running its own python script. This is what I have: ssh -t myuser@hostname screen python somepath.py -s 'potato' The problem with this is, after I run it, I have to manually ctrl + a + d, and exit out of the ssh session myself. Is there a way to do it all in one go without needing human interaction? EDIT: I have tried the suggested method of using -dm This is what I'm testing to make it easier to see: ssh -t user@host screen "top" remotely I see this: user 2557 0.0 0.2 27192 1468 ? Ss 13:35 0:00 SCREEN top user 2562 0.0 0.1 11740 932 pts/0 S+ 13:35 0:00 grep --color=auto SCREEN but if I do: ssh -t user@host screen -dm "top" I immediately get a Connection to host closed. And nothing in my grep ps aux | grep SCREEN user 2614 0.0 0.1 11740 932 pts/0 S+ 13:36 0:00 grep --color=auto SCREEN
You can use -d -m to your screen session to do it like: ssh myuser@hostname screen -d -m "python somepath.py -s 'potato'" That will create a new screen session, run your command in it and automatically detach you from it. That option is documented as -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. on the GNU documentation page for screen
Remotely starting a screen session through ssh and closing the ssh session immediately
1,381,981,716,000
I'm looking at http://taint.org/wk/RemoteLoginAutoScreen to setup my server so it autostarts a screen session when I login via SSH. I have added the following to my .bashrc: # Auto-screen invocation. see: http://taint.org/wk/RemoteLoginAutoScreen # if we're coming from a remote SSH connection, in an interactive session # then automatically put us into a screen(1) session. Only try once # -- if $STARTED_SCREEN is set, don't try it again, to avoid looping # if screen fails for some reason. if [ "$PS1" != "" -a "${STARTED_SCREEN:-x}" = x -a "${SSH_TTY:-x}" != x ] then STARTED_SCREEN=1 ; export STARTED_SCREEN [ -d $HOME/lib/screen-logs ] || mkdir -p $HOME/lib/screen-logs sleep 1 screen -RR && exit 0 # normally, execution of this rc script ends here... echo "Screen failed! continuing with normal bash startup" fi # [end of auto-screen snippet] The catch is that I always have a detached named screen session running a rails application server. Now when I login I am put into this session. Is there anyway to modify the above code to not select the session either by name or some other value? If the detached session is the only screen session then I would like to start a new screen session. Another issue that I am encountering is that when I detach I am completely logged out of my SSH connection as opposed to just leaving the screen session.
Change it to: if [ -z "$STARTED_SCREEN" ] && [ -n "$SSH_TTY" ] then case $- in (*i*) STARTED_SCREEN=1; export STARTED_SCREEN mkdir -p -- "$HOME/lib/screen-logs" screen -RR -S main || echo >&2 "Screen failed! continuing with normal bash startup" esac fi That is attach (or create) the screen session called "main" instead of the other one, and don't exit after screen has returned successfully.
Problems with automatically starting screen on SSH login
1,381,981,716,000
I've been trying to set up an automated backup system for a minecraft server, and I'm having trouble with screen, specifically when using 'screen -r sessionname -X "/var/minecraft/somebatchfile"', nothing happens. My process flow is somewhat like this at the moment: screen -m -d -S minecraft /var/minecraft/bin/server_nogui.sh This starts the minecraft server without any trouble. However, the issue is that even simple followups like this fail: screen -r minecraft -X "stop" I get no error message or success message, and the server does not actually disconnect clients and shut down, like it should. I assume I'm doing something wrong, but I don't know what. Is there some obvious mistake I'm making? I've read the man page a bit but I'm having no luck figuring it out myself.
You have to give the parameter -X a screen command, I think you want to "stuff" a minecraft-server command to the screen session. screen -r minecraft -p 0 -X stuff "stop $(printf '\r')" The printf send a carriage return, so the command "stop" gets executed. -p 0 makes sure the characters are sent to the initial Screen window. For sending it over ssh you have to enclosure the command in " " (you could also use ` `, but that wouldn't let you do the command substitution). ssh -t -i ~/.ssh/id_dsa server_user@server_address "screen -r minecraft -X stuff "even other_server_name is getting in on the action\! $(echo -ne '\r')"" Beware that ! is a reserved word, you have to escape it. It is also possible to include a user generated newline into the command to execute it: ssh -t -i ~/.ssh/id_dsa server_user@server_address "screen -r minecraft -X stuff 'even other_server_name is getting in on the action! '" Escaping ! isn't necessary here.
Why is screen seemingly doing nothing with commands passed with -X?
1,381,981,716,000
When in a screen session via ssh, if I attempt to connect to another host via scp or ssh and the auth fails, any subsequent text I type in the terminal will not be displayed, however it is being entered and can be executed. [user@host Oracle]$ scp user2@host2:/path/to/files . user2@host2's password: Permission denied, please try again. user2@host2's password: [user@host Oracle]$ [user@host Oracle]$ [user@host Oracle]$ [user@host Oracle]$ [user@host Oracle]$ [user@host ~]$ [user@host ~]$ What you can't see above is that I did 'cd' on the last line. It executed but output stays on the same line. ^C will give me a new line. Is there a way to recover without losing my screen session?
stty sane, or more specifically stty echo, should turn echo back on. (stty sane will fix other terminal input or output oddities such as newlines not going back to the left margin.) Ssh (and most other programs) turn echo off for the password prompt, i.e., the characters you type are not displayed (echoed) to the screen. stty -echo is a shell command with the same effect. Normally echo should be turned back on (like stty echo) after the password prompt; this is a bug in either ssh or some other software at play here such as your system libraries or terminal emulator.
Screen, remote login failure, and disappearing text