date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,448,250,142,000
I've noticed that when running screen the process identified with it actually shows up in capitals. Linux Debian Wheezy. Here an example with me ssh'in into a machine, running screen -S test and then running top there. me@host:~$ ps x PID TTY STAT TIME COMMAND 4177 ? S 0:00 sshd: me@pts/0 4178 pts/0 Ss 0:00 -bash 4260 ? Ss 0:00 SCREEN -S test 4261 pts/1 Ss 0:00 /bin/bash 4813 pts/1 S+ 0:00 top 5891 pts/0 R+ 0:00 ps x me@host:~$ Is there any reason for this capitalisation? I don't think I've seen any other programs in capitals like this. Screen lives on the filesystem as a lower case binary: me@host:~$ which screen /usr/bin/screen me@host:~$ l /usr/bin/screen -rwxr-sr-x 1 root utmp 402K Sep 4 05:07 /usr/bin/screen me@host:~$ file /usr/bin/screen /usr/bin/screen: setgid ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, BuildID[sha1]=0x035fa489e79088829da70a87252e4da70fc4a6bf, stripped me@host:~$ If this is accepted behaviour or perhaps a new trend I'm not aware of?
The developers chose to do this to simplify killing stray screen processes. Refer to the source repository: the change was made between versions 2.3 (February 25, 1991) and 3.1 (September 9, 1991), which includes these comments from CHANGES: when the socket has been removed, send a SIGCHLD to the poor SCREEN process and it will try to recover. then try a 'screen -r' again. all the socket stuff lives now in an extra file. and from README: screen -list screen -ls Show all available sockets. If there are (DEAD???) sockets, you may consider removing them. If there are sockets missing, you may send a SIGCHLD to its process 'SCREEN' and the process will re-establish the socket. (think of someone cleaning /tmp thoroughly). If they had not changed the name so thoroughly, there was the risk of users signalling the wrong process.
screen process in capitals
1,448,250,142,000
I am attempting to keep a nested ssh session inside of a byobu/screen window, which I also connect to over SSH with Putty on Windows. However the nested SSH session has no color. Here's what I'm talking about: On the left you have byobu connected to wreckcreations with no color. On the right you have Putty connected directly to wreckcreations with color. Note that normally byobu has color when working locally. I tried messing with $TERM, $PSI, and other variables to no avail. Any idea's what would cause this?
It could be many things. Please provide the output of: echo $TERM echo $LS_COLORS typeset -p LS_COLORS alias ls tput setaf 1 | od -c echo "$(tput setaf 1)red$(tput sgr0)" Expected results: xterm (optional, see below) no=00:... (or similar, should not be empty) declare -x LS_COLORS="no=00:..." (ditto) alias ls='ls --color=auto' (or similar) 0000000 033 [ 3 1 m 0000005 red (in red) My guess: TERM is set to something unusual, and dircolors doesn't know about it, therefore ls doesn't know what colors to use. If this is the case, running the above commands inside your byobu/screen session, you would see: screen (or screen-something) (nothing) (nothing) 0000000 033 [ 3 1 m 0000005 red (in red) Confirm that this is the case by running: dircolors -p | grep "^TERM $TERM$" I would expect it to print nothing. The simplest fix, depending on your configuration, would be: dircolors -p > ~/.dircolors echo "TERM $TERM" >> ~/.dircolors
Nested ssh session inside screen has no color
1,448,250,142,000
Let us imagine I have only one terminal. To overcome this trouble I use screen, so happy! However, I need to connect to another computer over ssh, to prevent to open several connections I want to run screen on this window, but if I do that I'll have problems with key binding. Is there any solution?
You can pass commands from one screen sessions to it's sub-screen session with Ctrl+a a (it send Ctrl+a to the sub-screen) For example: To detach the sub-screen: Ctrl+a a-d Go to the next screen: Ctrl+a a-n Go to the previous screen Ctrl+a a-p
Is it possible to merge two screen sessions chained?
1,448,250,142,000
I have a game server running on Centos 7 via screen. I can confirm that the game server is running, I can connect to it with the client, and ps faux gives me this output: steam 10111 0.0 0.0 127904 3028 ? Ss Jul09 0:00 SCREEN steam 10112 0.0 0.0 115444 3548 pts/2 Ss Jul09 0:00 \_ /bin/bash steam 16558 0.0 0.0 113180 2700 pts/2 S+ Jul09 0:00 \_ /bin/bash ./avorionsrv.sh steam 16564 4.1 5.7 2276908 944748 pts/2 Sl+ Jul09 234:32 \_ ./bin/AvorionServer --gala[...] However, I can't reattach to that screen session (it was started by the "steam" user): [steam@atlantis ~]$ screen -r There is no screen to be resumed. And trying to get the list of screens yields "no sockets found" [steam@atlantis ~]$ screen -ls No Sockets found in /var/run/screen/S-steam. The same happens with the root user, and a find in the screen socket directory tells me that there is nothing there. ┌─(/root)──────────────────────────────────────────────────(ROOT@atlantis:pts/0)─┐ └─(11:54:05)──> find /var/run/screen <──(Fri 13 Jul)─┘ /var/run/screen /var/run/screen/S-root /var/run/screen/S-steam Any ideas on how to reattach to that screen?
This sounds like your screen socket files got deleted out from under screen. You can trigger screen to recreate them like so by send the SIGCHLD signal to them using the kill command: $ kill -CHLD 30860 $ ls /var/run/screen/S-username/ 30860.pts-4.localhost Where the PID, 30860, is the PID of screen. There are additional methods highlighted in the FAQ titled: archived Gentoo Wiki FAQ. References How do I reconnect to a lost screen (detached, missing socket)? archived Gentoo Wiki FAQ
Screen active but no sockets in /var/run/screen
1,448,250,142,000
I am using screen to communicate with arduino over serial port, i start screen like this: screen /dev/ttyACM0 115200 then I try to send a command but every key I press on the keyboard get sent straight away, how to make it wait until I press Enter key before sending input to arduino? Here's my serial device /dev/ttyACM0 settings: $ sudo ssty -F /dev/ttyACM0 -a speed 115200 baud; rows 0; columns 0; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^H; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O; min = 100; time = 2; -parenb -parodd -cmspar cs8 -hupcl -cstopb cread clocal -crtscts -ignbrk brkint ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8 -opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 -isig -icanon iexten -echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc My .screenrc file is empty.
I don’t work with Arduino devices, so I can’t be of specific help, but in lack of other answers I can try and give you some general hints (for the UNIX/Linux side) as to how address your particular problem. Unfortunately there’s no setting you can give to your serial port to make it send data in lines. That is a responsibility of the application, i.e. the terminal emulator you use, screen in your case. But I’m afraid (AFAIK) that neither screen nor other terminal emulator applications allow a line-oriented mode of what you type. You might rather obtain something usable with tools like expect, or minicom’s companion command runscript (which is along the lines of expect), which normally do send data in lines. Otherwise, as another possibly good resort, you might implement a (very) rudimental line-oriented “terminal application” yourself. As crazy as this normally is, it might turn out very easy to do it for your specific case, with just a few commands from the shell. ( set -e prev_settings="$(stty -g -F /dev/ttyACM0)" trap 'stty "${prev_settings}" -F /dev/ttyACM0' EXIT stty -F /dev/ttyACM0 raw -echo -echoe -echok -echoctl -echoke cat < /dev/ttyACM0 & cat > /dev/ttyACM0 ) The set -e just serves to quit execution at the first error (if any) encountered by the following commands. The stty -g saves the serial port’s current settings. The trap sets up the restoring of the saved settings on EXIT from the commands. The stty raw ... sets (what I think should be) the sanest (for this particular case) settings to the serial port. The first cat command just outputs to your terminal window whatever comes from the Arduino. The second cat command sends to the Arduino whatever you type from then on. To quit this bunch of commands, just type Ctrl-C. The “trick” here is simply that the cat command, by design, sends output line by line, as you requested. On the other hand, the input cat command (the first cat) shows you immediately each single character coming from the Arduino thanks to the stty raw setting. If the Arduino happens to send streams of data, you might want to add the min 100 time 2 settings that I see in your current stty -a output. That might display things a bit faster in case of streams. The parentheses serve to run these commands in a subshell, which is handy to restore the tty settings thanks to the trap command. You may also put the commands in a script (naturally without the parentheses) and then run that. Note that it’s best if you quit or otherwise suspend any other application that might access the serial port while you use the above commands, otherwise they might interfere with each other. This simple solution works best if your Arduino device does not echo back what it receives. If it does, you’ll just see twice whatever you type, once for your actual typing, and again for the echoing from the Arduino. The thing is, what you see on your terminal cannot be controlled by Arduino because of the line-oriented setup. It can be possible to turn off that too (by acting locally to turn off character displaying), but I suppose you prefer to see what you’re typing before you send it to Arduino. One final (and hopefully irrelevant) thing I note is that your serial port is classified as ttyACM. This normally means that the serial port you’re using has advertised itself as capable of some additional feature, otherwise it would have been classified by the system as a more generic ttyUSB port. Being a ttyACM is more typical of specialized serial devices (such as 3G/4G cellular modems) rather than simple serial ports. However it can be just a serial port with a silly chip, and in practice this should not pose any real problem, but who knows.. HTH
How to send input text (in screen) to serial port, a line at a time (not character at a time)?
1,448,250,142,000
I am using GNU screen with a horizontal split, but it is not always easy to decide which pane is active (e.g. when using a program like top in one of the panes). Is it possible to change the color of the text in the caption, when the pane is active? I use these settings right now: hardstatus alwayslastline "%{= G}%{g}[ %{G}%H %{g}][ %?%-Lw%?%{R} %n*%f %t %{g}%?%+Lw%? %{g}]%=%{g}[ %{W}%c:%s %{g}]" caption splitonly "%{= g}[%n %t]" It would be nice to be able to change the color of %n %t to R when the pane is active, or some other way of highlighting the pane.
I looked at the STRING ESCAPES section of the screen man page and found what you may be after. The ? escape is like an if statement and the : escape is like an else statement. The F escape is true when that window has the focus. So the if-then-else statement for the if active then, else would look like this (padding added for readability): %? %F active-window options %: inactive-window-options %? The original option was %{= g} (pad string to display width and green) changing the active screen text to bright red will look like this: caption splitonly "%?%F%{= R}%:%{= g}%?[%n %t]" https://www.gnu.org/software/screen/manual/screen.html#String-Escapes
GNU screen split: how to show active pane in caption
1,448,250,142,000
I am using the following screen status line, configured in my screenrc: I configured it using the following line: hardstatus alwayslastline hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f %t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]' I did not create this theme, I don't remember where I found it, but I really like it. I am now converting my configuration to tmux and I can't seem to replicate this configuration in my tmux.conf. I got this far: set -g status-bg black set -g status-fg white set -g status-left '#[fg=green]#H' set-window-option -g window-status-current-attr bright set-window-option -g window-status-current-bg red Which produces this line: ] Please ignore the different hostname, it's on a different server What configuration can I use in tmux to produce a status line similar to the first one? Thank you!
With the exception of the red brackets around the highlighted window, this is the closest approximation that I can easily configure in tmux 1.5: # default statusbar colors set -g status-fg white set -g status-bg default # default window title colors set-window-option -g window-status-fg white set-window-option -g window-status-bg default set-window-option -g window-status-attr dim # active window title colors set-window-option -g window-status-current-fg white set-window-option -g window-status-current-bg default set-window-option -g window-status-current-attr bright # statusline set -g status-left '#[fg=green][ #H ][' set -g status-right '#[fg=green]][ #[fg=blue]%Y-%m-%d #[fg=white]%I:%M #[fg=green]]' If you want the highlighted window in red, use: set-window-option -g window-status-current-fg red
Convert gnu screen status line to tmux status line
1,448,250,142,000
So I have 2 terminals open in front of me; /dev/pts/1 - 'the controller' /dev/pts/2 - 'the receiver' I am currently using ttyecho to execute commands in /pts2 from /pts1. I can list the screens - ttyecho -n /dev/pts/2 screen -ls fine from /pts1 and see the results in /pts2. I can attach to a screen ttyecho -n /dev/pts/2 screen -x [blah] from /pts1 on /pts2 fine.. But what I can't do, is when attached to a screen then detach from it. So if /dev/pts/2 is then inside a screen, I am trying to detach from it by executing a command using ttyecho from /dev/pts1 I've tried sending... ttyecho -n /dev/pts/2 ^a+d ttyecho -n /dev/pts/2 screen -d -r ttyecho -n /dev/pts/2 screen -D -RR ttyecho -n /dev/pts/2 screen -d -r ttyecho -n /dev/pts/2 screen -DRi ttyecho -n /dev/pts/2 Ctrl+a+d ttyecho -n /dev/pts/2 Ctrl+a d ttyecho -n /dev/pts/2 CTRL + A ttyecho -n /dev/pts/2 control+a So I guess what I need is either: A command I can send that will detach the screen OR Someway to send some kind of pseudo keyboard commands via ttyecho to that other screen to detach it. Any help most appreciated.
You can do $ screen -ls This will list all the screen sessions like this. There are screens on: 8365.pts-6.vm2 (Attached) 7317.pts-1.vm2 (Attached) 2 Sockets in /var/run/screen/S-root. Then you can detach any screen session with the help of screen id. For eg: $ screen -d 8365 [8365.pts-6.vm2 detached.]
How to remotely detach a screen from another terminal
1,448,250,142,000
I'm always forgetting to logoff when ssh-ing somewhere. After I reopen my notebook, a screen window with this running ssh is unresponsive. I have to create another window, $ killall ssh, and only then can I re-ssh back. Is there a way to kill this ssh using some shortcut? Or is there a way to make ssh try to reconnect automatically? Or just return the local prompt to me faster?
Try the following , ~. Disconnect. ~^Z Background ssh. ~# List forwarded connections. ~& Background ssh at logout when waiting for forwarded connection / X11 sessions to terminate. ~? Display a list of escape characters. ~B Send a BREAK to the remote system (only useful for SSH protocol version 2 and if the peer supports it). ~C Open command line. Currently this allows the addition of port forwardings using the -L, -R and -D options (see above). It also allows the cancellation of existing remote port-forwardings using -KR[bind_address:]port. !command allows the user to execute a local command if the PermitLocalCommand option is enabled in ssh_config(5). Basic help is available, using the -h option. ~R Request rekeying of the connection (only useful for SSH protocol version 2 and if the peer supports it).
Kill disconnected SSH session running in `screen`
1,448,250,142,000
I want to have a script running in screen at startup. This doesn't work: @reboot pi screen -d -m /home/pi/db_update.py however running this manually as user pi works: screen -d -m /home/pi/db_update.py Any idea on what I am missing?
Instead of adding @reboot pi ... to /etc/crontab you should run crontab -e as user pi and add: @reboot /usr/bin/screen -d -m /home/pi/db_update.py Make sure to use the full path to screen (just to be sure, it works without it), and that the /home/pi is not on an encrypted filesystem (been there, done that). The command cannot depend on anything that might only be accessible after either the cron daemon has started, or the user is logged in. You might want to add something to db_update.py (writing to a file in /var/tmp to see that it actually runs, or put a time.sleep(600) at the end of the python program to allow enough time to login and connect. Tested on Lubuntu 13.04, python 2.7.4 with the following entry: @reboot screen -d -m /home/anthon/countdown.py and the countdown.py: #!/usr/bin/env python import time for x in range(600,0,-1): print x time.sleep(1) (and chmod 755 countdown.py)
Running `screen` through a @reboot cron job
1,448,250,142,000
I use myscript > my.log 2>&1 & to run a script and collect it's output - so that when I logout - the script will still be running. It I were to start it with myscript & - it will be terminated right after logout. But that's a strange effect: all that > my.log 2>&1 & does is redirect stderr to stdout... Why > my.log 2>&1 & causes the job to sustain log out?
Normally if you put something in the background it will continue to run even after its parent shell exits. In fact, I can create a test case like this: /bin/sh -c 'while true; do echo hi; sleep 5; done' & and then exit the shell and using ps I can see it's still running, forever, until I kill it. There is one difference between redirecting the output and not: if you don't redirect the output and you exit your shell, then the stdout/stderr file descriptors are closed and the next time you try to write to them the write operation will fail. If your script is checking for that, or running with the -e (exit on error) option set, then your script will stop. Compare the behavior of the above with this version: /bin/sh -c 'while true; do echo hi || exit 1; sleep 5; done' & or /bin/sh -ec 'while true; do echo hi; sleep 5; done' & If you leave this running, exit the shell, and use ps you'll see that when it tries to run the echo it will fail, and exit. If you were to redirect the output to a file then obviously the write will not fail anymore and the script will continue to run.
Why `> my.log 2>&1 &` causes the job to sustain log out?
1,448,250,142,000
I have a raspberry pi on which I'm running some services. I need to be able to ssh into the machine and monitor those services. Currently, what I do is I log in, run screen, then create three windows and in each window run the script that runs the relevant service. Two of these are actually running as root (one monitors the network, another monitors some hardware connected to the pi). The third is running the actual service, and runs in my user. (The second is basically a proxy for the hardware to talk to the third.) In any case, this works great, except that when the pi gets rebooted for whatever reason (e.g. power failure), I have to set all this up again, which is tedious. What I would like is for the system to run screen in my user or startup automatically, with three windows created, two running processes as root and one in my user, such that when I log in, I can connect to that screen session and see everything running live. How would I do that?
As @DavidDai mentions in his comment, it would be best to run these as system services (e.g. by creating systemd service files or sysvinit startup scripts for them). That can be easier said than done, though. It is possible to keep doing it with screen. You just need to create a config file for screen, and use screen -c /path/to/screen/config (to override the default ~/.screenrc configfile). screen -t monitor1 0 sudo /path/to/monitor1.sh args screen -t monitor2 1 sudo /path/to/monitor2.sh args screen -t server 2 /path/to/service/script.sh If you want it to start with a particular window active, you can add a line like the following: select 1 See man screen for details. You'll also need to configure sudo to allow your user to run both monitor1.sh and monitor2.sh as root. This will not be started automatically when your rpi reboots. You'd have to login and start screen manually. For automatic startup under your uid, you could run it from an @reboot crontab entry (see man 5 crontab for details). You can attach to this screen session as your user. Alternatively, you could run a detached screen (e.g. screen -d -m -c /path/to/config) as root (e.g. from /etc/rc.local or cron as above) and dropping sudo from the first two windows, and adding it to the last: screen -t monitor1 0 /path/to/monitor1.sh args screen -t monitor2 1 /path/to/monitor2.sh args screen -t server 2 sudo -u username /path/to/service/script.sh This would be started up automatically whenever the rpi reboots. You would have to be root to attach to this screen session. Finally, if your monitoring scripts don't need to be run as root, you should run them as a less privileged user. Maybe create a new user and add them to a group with read access to whatever it is they need to monitor.
Setting up a screen session on system startup
1,448,250,142,000
I want to somehow generate a comprehensive "menu" of all possible ways to set up the GNU-screen "command characters" for a standard, off-the-shelf "US keyboard" and a specific terminal emulator, say xfce4-terminal. I imagine that this universe of possibilities would decompose into three lists: list A: all the possible values of the escape directive list B: all the possible values for the <CODE> parameter in the expression bindkey -k <CODE> command, together with the "null setting" (i.e. the .screenrc config in which no bindkey -k <CODE> command directive is used) list C: a mapping from any pair (a, b) (where a ∈ A, and b ∈ B) to an explicit description of how one would type the corresponding GNU-screen command character on a standard US keyboard, and assuming a specific terminal emulator (IOW, something equivalent to, for instance, "simultaneously press Ctrl and \"). Keep in mind, however, that these specs are a "best effort" by someone (me) who really does not understand the underlying basics. I hope that those who do understand these basics will be able to "read between the lines", and modify these specs as needed, while still retaining the spirit of the question (see Background), to render the question tractable. I realize that the "menu" I'm hoping for may be very large, but I figure that it can't be intractably so, since, after all, the number of keys on a standard US keyboard is finite and not ginormous, and the set of fingers one can use for this purpose is even more so. (In case it matters, I could further stipulate that I am only interested in key combinations consisting of at most, say, 2 sequential "key chords", with at most 3 keys per key chord. By "key chord" I mean "set of keys to be pressed simultaneously".) Background (aka tl;dr) This question is actually a follow-up to a comment by Gilles in a thread I started earlier. It turns out that most of what that comment says is beyond my grasp. I figure that there are some huge gaps in my understanding of the basics here, so big in fact that I cannot even articulate sufficiently clear questions to fill them. In a nutshell, it is a huge mystery to me that, for example, the key combination Ctrl + \ can be used to type the "command character" for GNU-screen, whereas other similar-looking key combinations, like (maybe) Ctrl + ', cannot 1. Without a clear understanding of the underlying basics from the user (like me), the search for a suitable GNU-screen command character reduces to a sequence of isolated proposals ("How about Ctrl + H? After all, no one uses that for anything else.") that the user evaluates in turn until an acceptable one pops up. How long this sequence of proposals and evaluations needs to go on depends on the size of the set of acceptable key combinations for that user. Clearly, this size will vary from one user to the next. In my case, it appears to be smaller than average, and as a result this approach has not yet given me an acceptable "command character" for GNU-screen. The approach, in any case, seems to me inherently inefficient. It make more sense to me to be able to choose the best option from an explicit "universe" (i.e. "exhaustive set") of possibilities. This is what I'm trying to get at here. EDIT: OK, after some studying, I now have a clear picture of how one types the (1-byte) characters in the ASCII range between \0001 and \0177, inclusive. These include all the "true" "control characters". Also, I figure that list A can be described as all possible pairs of integers between \0001 and \0377, although probably many of these pairs can be ruled out as completely impractical. (E.g., those in which the first element of the pair is common "printable character", such as "e" or "8"). I'm still trying to figure out the following: how to type the (1-byte) characters in the ASCII range \0200 to \0377, inclusive; I expect there will be some variation across terminals and terminal emulators on this, but I have no sense at the moment of how chaotic the variation is; is there a subset of these characters on which there is a substantial consensus? If so, I would love to know what these characters are (and how to type them) how to get useful values for list B; I realize that these values are termcap codes; my difficulty here is not having a way to identify those termcap codes that map neatly to a convenient key combination; e.g. I know that the code F2 maps to F12 (sic), but I imagine that most termcap codes don't have such a neat association with a single key. how to complete list C, even for a specific terminal emulator, and the "null setting" from list B. 1Please, don't attempt to explain this mystery to me: many very knowledgeable, and very patient, people have tried, and I still don't get it. The "knowledge gap" between those who understand what's going on and me is so great that their answers are invariably as baffling to me as what they aim to address. What I'm hoping to achieve with this post is precisely to work around this huge knowledge gap, by casting the question as a search for, in essence, an algorithm (to construct a prescribed finite set of possibilities) that could be implemented by even someone who does not understand the underlying basics.
To understand the answer to this question, you need to have some understanding of how keyboard input is processed. I refer you to How do keyboard input and text output work? for background. In this answer, I'm going to explain the relevant part in a different way, but I'll assume some general familiarity given by my earlier answer. My answer here concerns typical unix systems; non-unix systems may behave differently. I will make some simplifications here and there; the additional complications are not relevant to answering this question. (This answer is complicated enough as it is.) Most communication and storage, including the communication between a terminal-based application and a terminal (hardware or software), takes the form of a stream of bytes. A byte is a unit of information that can take 256 different values; it can be subdivided in 8 bits. Bytes are represented by a number between 0 and 255. In order to transmit information, the parties need to agree on a way to encode this information as bytes. There are multiple ways to encode streams of characters as streams of bytes, but all of them are based on ASCII in one way or another. ASCII defines a correspondence between 7-bit values ranging from 0 to 127 and a set of 128 characters; this leaves an unused bit in each byte. The 128 characters fall into two categories: 95 printable characters: letters (A–Z, lowercase and uppercase), digits (0–9), space, some punctuation; 33 control characters. Control characters encode orders and ancillary information sent to or from a terminal such as “move the cursor to the next line”, “ring the bell”, “wait for me”, “goodbye”, etc. Historical terminals introduced a key labeled “Control” (or “Ctrl” for short), which allowed users to enter control characters. To keep the electronics of the terminal simple, pressing Ctrl together with a key would perform a simple bit mask in the byte value normally sent by the character. For example, A sends the character A represented by the byte 65 (1000001 in binary); Ctrl+A sends the character represented by the byte value 1 (0000001 in binary), which is known as the “control-A” character, often written ^A. Most control characters correspond to an uppercase letter, with the bit pattern 10xxxxx, with bit 6 set to 0 instead of 1. That accounts for 26 of them. 6 more control characters correspond to the punctuation characters that also have a bit pattern of the form 10xxxxx: these are @[\]^_ (see the ASCII printable character chart. In addition to the range 0–31, the character 127 is also a control character; it's known as “control-?” (? is 0111111; control-? is 1111111). Over the years, non-ASCII byte values have been assigned different meanings. The world is converging to Unicode as the set of all characters anybody might want. The Unix world (as well as the Internet) has mostly standardized on UTF-8 as a way to encode characters as byte sequences. UTF-8 maintains compatibility with ASCII by assigning the same character as ASCII to any byte in the range 0–127, and using sequences 2 to 4 bytes in the range 128–255 to represent the million or so other characters. Some other character encodings are used in the unix world; most are based on ASCII and have different meanings for bytes above 128. I can now answer one of your follow-up questions: how to type the (1-byte) characters in the ASCII range \0200 to \0377 That depends what character encoding you use. If you use UTF-8, the most common one, sending these individual bytes is impossible, because they're only used as part of sequences of 2 to 4 bytes that represent a single character. As for list A: all the possible values of the escape directive that's just byte values. The escape directive requires a two-byte parameter. If Screen receives the first byte value from the terminal, it decides that its escape key has been pressed. If the next byte sent by the terminal is the second byte from the escape setting, then Screen decides that you wanted to send that first byte to the application running inside the Screen window after all. The description of the bind command explains how to specify byte values in a way that Screen understands. Where the documentation reads “character”, read “byte” instead. Before we get to list B, we need to understand keychords. A keychord is the press of a key together with modifiers such as Ctrl, Shift, etc. We saw earlier that all information transmitted by the terminal is encoded as a stream of bytes. To keep things simple, all printable characters are encoded in the standard way, as one byte in the range 32–126 if they're ASCII characters and as bytes in the range 128–255 for other characters. This leaves only control characters to encode function keys and characters with modifiers other than Shift. But there are only 33 control characters! A few function keys send a control character. For example, the Tab key sends ^I (byte value 9), because byte 9 is the TAB control character that instructs a printer to move to the next tab column. The Return key sends ^M (byte value 13), because byte 13 is the CR control character that instructs a printer to move its head to the beginning of the line. For similar reasons, Escape sends ^[, and BackSpace sends either ^H or ^? due to some historical waffling that I won't discuss here. Most function keys and keychords send an escape sequence: a sequence of bytes starting with byte 27, the escape character (ESC) defined by ASCII, which happens to be ^[ (control-[). Different terminals sent different escape sequences. There are standards, but they don't define encodings for all keychords, far from it, and to some extent there are competing standards. We're now ready to understand list B: all the possible values for the <CODE> parameter in the expression bindkey -k <CODE> The Screen documentation explains that these codes are termcap keyboard capability names. Termcap is a programming library that applications can use to abstract themselves from the variations between terminals. (It has now been mostly supplanted by Terminfo.) The Termcap database specifically contains information about the terminal such as the number of lines and columns (back when Termcap appeared, terminals were hardware devices, for which the concept of resizing didn't apply), the byte sequences (often beginning with ESC) that an application could use to perform operations such as moving the cursor or clearing the screen, and the byte sequences send by various keys. The symbolic names given by Termcap to function keys are what you can use after bindkey -k. The Termcap manual lists all the entries in that database. The entries all have two-character names; the FreeBSD manual also gives a slightly more expressive name for each entry. The entries where FreeBSD lists key_SOMETHING in the first columns are the ones that describe function keys; the <CODE> you need for bindkey -k is the name in the second column, such as kl for Left, k1 for F1, F1 for F11, etc. You'll notice that this database is missing a lot of keychords. If there's no entry for a keychord in this database, then there's no name you can use for the key with bindkey -k. Note that the set of supported keys varies from unix variant to unix variant. bindkey can also be passed an escape sequence. To use this feature, you need to know what your terminal sends for the keychord you're interested in. While different terminals send different escape sequences for the same keychord, going from escape sequence to keychord is, fortunately, rarely ambiguous: very few escape sequences correspond to different keychords on different terminals. You can find out what escape sequence a keychord sends by pressing Ctrl+V then the keychord. In a terminal in its default mode, as well as on the command line of all common shells, Ctrl+V means “interpret the next byte literally”. If it's followed by an escape sequence, this causes the ESC byte to be inserted literally instead of initiating the parsing of an escape sequence. Since escape sequences almost always consist of printable characters after ESC, this effectively inserts the escape sequence literally. For example, press Ctrl+V then Ctrl+Left to see what escape sequence Ctrl+Left sends: you'll see something like ^[O5D where ^[ is a visual representation of the ESC control character. (Once again, your terminal may send a different escape sequence.) As for the null setting, when Screen reads an ESC byte, it enters escape sequence parsing mode. Each new byte is added to the accumulated escape sequence. If the accumulated sequence has an associated binding, Screen exits escape sequence parsing mode and fires the binding. If the accumulated sequence is not the prefix of any sequence with an associated binding, Screen exits escape sequence parsing mode and the accumulated sequence is discarded. So the null setting here is a complicated form of “nothing happens”. After all this work, let's turn to list C: a mapping from any pair (a, b) (where a ∈ A, and b ∈ B) to an explicit description of how one would type the corresponding GNU-screen command character on a standard US keyboard, and assuming a specific terminal emulator As I hinted above, specific terminal emulator is important here: different terminals encode keychords in different ways, and some terminals can be configured in different ways. The mapping doesn't correspond to a pair (a, b): A × B is not an interesting set. Most keychords are mapped to either a printable character (which, as we saw above, extends A) or an escape sequence (which, as we saw above, extends B). In other words, the mapping is to a superset of A ∪ B. Unfortunately for you, many terminals don't fully document how to send escape sequences. Fortunately for you, this is rarely needed. Instead of working from escape sequence to keychord, work from keychord to escape sequence. This can be determined for each terminal using Ctrl+V as described above. Some terminals, notably xterm, can be configured to encode keychords in a systematic way. See Problems with keybindings when using terminal for an Emacs-oriented discussion. Unfortunately, this does not include the vte library that many terminal emulators use, especially in the GNOME world.
How to make a comprehensive set of possibilities for defining GNU-screen "command characters"?
1,448,250,142,000
In bash I can hit Ctrl + a and go to first of the command line. But in screen Ctrl + a does not do this. How do I go to first of command line in screen?
You can press Ctrl+a followed by a to go to the beginning of the line. The a sends a Ctrl+a to the terminal.
How do I go to beginning of command line when I am inside the screen?
1,448,250,142,000
I'm seeing some slightly odd behaviour when using GNU Screen 4.00.03 on a Red Hat Enterprise Linux 6.4 system. If I connect without Screen, looking at the logs I can see each line is terminated with CRLF (0x0D 0x0A), exactly as expected. If I connect and run Screen, lines with two or more characters are terminated with CRLF as expected. Lines with no printed characters (eg from running a bare echo) are terminated only with LF (0x0A), and most bizarrely of all, lines with a single printed character (eg echo x) are terminated with BSLF (0x08 0x0A). I'm seeing this with PuTTY, and the above logs are from PuTTY logs. I'm also seeing this with automated Python frameworks using Pexpect, so I'm not blaming PuTTY for this. What's going on? How do I stop it?
That's an optimisation done by screen. When you type echo<Cr> in screen. Because of the local echo and the icrnl and onlcr settings of the pseudo terminal device in the screen window, the \r\n sequence is sent to master side (to screen). screen implements a terminal emulator where \r is meant to bring the cursor to the beginning of the line and \n to move the cursor down. To do that, where a terminal emulator like xterm would do X API calls to move the cursor to the beginning of the line, screen has to send escape codes to the host terminals it is attached to to tell it/them to move the cursor to the left hand side of the screen window. In case you've split the window vertically, that means send cursor positioning escape sequences to wherever the left hand side of the screen windows is. If not or if on the left hand side of the host terminal, screen would just pass those \r and \n characters along so that the cursor be moved to the beginning of the line and one line down on the host terminal as well (since all terminals treat \r and \n the same in that instance). Now, echo runs and outputs a \n character. Because of onlcr again in the screen window tty, screen receives \r\n again. \r tells it to move to the beginning of the line, but the cursor is already at the beginning of the line, so no need to do anything which is why the host terminal doesn't receive a second \r character. Then to move the cursor down because of the \n it receives, screen sends \n to the host terminal. You can verify that by running in screen: printf '\r\r\r\r' You'll notice that screen only sends one \r character to its host terminal.
Line endings when using GNU Screen
1,448,250,142,000
screen's man page mentions a "Multi display mode" at one place: -x Attach to a not detached screen session. (Multi display mode). It's the only place where "Multi display mode" is mentioned. What is it? Is understanding "Multi display mode" important for any other screen's options or commands?
Using screen -x allows you to connect to a session that it currently attached, without forcing it to detach. For example, if you do this in two separate xterms, you will see input and output of both instances simultaneously. This is useful when logging in from several locations; it avoids having to reattach once you go back to the location where you first attached to screen. To answer the "is it important?" part of your question, I would say no; if you're just starting with screen, don't worry about it; the feature will make sense if you ever fall into the scenario above, but it's not a hard requirement either.
What is screen's "Multi display mode"?
1,448,250,142,000
Is there a way to send the output of a command to a GNU Screen's copy mode buffer. I'd like to type something like this: $ echo 'this is an example' | screen_send_to_copy_mode or, maybe C-a Some key and then, after that, when I pressed C-] I would get this is an example as an output. Is it even possible?
You could do something like: screen_send_to_copy_mode() ( tmp=$(mktemp) || exit cat > "$tmp" && screen -X readbuf "$tmp" ret=$? (sleep 2; rm -f -- "$tmp")& exit "$ret" ) echo 'this is an example' | screen_send_to_copy_mode
How to send command output to GNU Screen's copy mode buffer
1,448,250,142,000
Scrollability of text in some terminals: | tty | xterm | urxvt | guake | terminator screen | Y | Y | Y | Y | Y tmux | N | N | Y | N | N I notice in this answer that scrolling doesn't work when using tmux. But I can scroll in urxvt. How can I have that behaviour in other terminals?
Add set -g terminal-overrides "xterm*:smcup@:rmcup@" to your tmux config and restart tmux. If you are not using a terminal matching 'xterm*' you'll have to change it of course.
Scrollability of text when using tmux?
1,448,250,142,000
I would like to send a command to a screen session and if possible get the output. My attempt at sending a command to a screen session is as I found on this website and lots of others, but it doesn't seem to work: root@server [~]# screen -X "script -a -c 'ls -l' /tmp/command.log" && cat /tmp/command.log cat: /tmp/command.log: No such file or directory root@server [~]# Note there is only 1 Screen session running, so I have omitted -S and -p (tried it with those too and no effect). For example: root@server [~]# screen -p 0 -X stuff "script -a -c 'ls -l' /tmp/command.log" && cat /tmp/command.log cat: /tmp/command.log: No such file or directory
First, read sending text input to a detached screen. You do need -p to direct the input to the right window. Also, the command won't be executed until you stuff a newline (CR or LF, the interactive shell running inside screen accepts both). That's: screen -p 0 -X stuff "script -a -c 'ls -l' /tmp/command.log$(printf \\r)" && cat /tmp/command.log There's a second problem, which is that the screen -X stuff … command completes as soon as the input has been fed into the screen session. But it takes a little time to run that script command. When cat /tmp/command.log executes, it's likely that script hasn't finished; it might not even have started yet. You'll need to make the command running inside screen produce some kind of notification. For example, it could signal back that it's finished, assuming that the shell within Screen is running on the same machine as Screen. sh -c ' sleep 99999999 & screen -p 0 -X stuff "\ script -a -c \"ls -l\" /tmp/command.log; kill -USR1 $! " wait cat /tmp/command.log '
Trouble sending command to detached Screen session
1,448,250,142,000
I am trying to create an Upstart job that starts a new screen session on boot, in which I would like to automatically start a java executable. Here is the .conf file I am currently trying to get to work, although I have tried several others: description "Run the bungeecord jar" start on (local-filesystems and net-device-up IFACE=eth0 and runlevel [2345]) stop on runlevel [016] exec start-stop-daemon --start -c ridog --exec /usr/bin/screen -- -dmUS BungeeCord java -server -XX:UseSSE=4 -XX:+UseCMSCompactAtFullCollection -XX:MaxPermSize=356m -XX:ParallelGCThreads=6 -XX:+UseConcMarkSweepGC -XX:+DisableExplicitGC -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing -XX:+UseCompressedOops -XX:+AggressiveOpts -Xmx256M -jar BungeeCord.jar pre-stop script screen -S BungeeCord -X foo "end^M" end script To my knowledge, the script seems to work fine, I can run sudo start bungeecord and get the intended result, however, restarting the machine does not work. Instead, I get this error in the /var/log/upstart/bungeecord.log: Cannot make directory '/var/run/screen': Permission denied I've looked up this error and the search results are obscure and inconclusive. I've tried running the command as root, this removes the error but still no screen session. I've tried different commands like this: su ridog -c "screen -dmS BungeeCord java -jar /home/ridog/BungeeCord/BungeeCord.jar"
Problem solved, I switched from using upstart to using cron. It was much more simple and everything works great now. For anyone reading this that might be curious as to how I did it, I made a simple shell script: #!/bin/bash java -Xms256M -Xmx256M -jar /home/ridog/BungeeCord/BungeeCord.jar And set it to run on startup with a new line in crontab -e: @reboot screen -dmS BungeeCord sh /home/ridog/BungeeCord/run.sh Thanks for your help!
How do I start a screen session using an upstart job with a non privileged user?
1,448,250,142,000
When attaching to the same tmux sessions from multiple computers using ssh and tmux attach, my screen looks like: ------------------------- $> |........ |........ |........ |........ |........ -----------------........ ......................... ......................... I was wondering if there is a command to get rid of the viewport
Probably the width/height (colums/rows) of the "original" terminal form which you launched te tmux session is lower than that of the terminal you're attacching from. Personally I don't use tmux, but that happens to me with screen when I launch from a 80x25 terminal and then I attach from another terminal with 80x50 columns/rows.
Tmux viewport caused by multiple concurrent sessions
1,448,250,142,000
When I use the screen program, the prompt doesn't get interpreted and is just the following: \u@\h:\w$ How can I correct this?
screen is running dash or other shell which doesn't recognize those bash-specific prompt escapes inside PS1. Either set the SHELL environment variable to /bin/bash before starting screen, run it as screen -s /bin/bash or set the following in your ~/.screenrc: shell /bin/bash The ~/.screenrc command has precedence over the -s command line switch, which has precedence over the $SHELL envvar. If neither is set /bin/sh will be used.
Using GNU screen, I get raw prompt with backslashes
1,448,250,142,000
I'd like to get Terminfo for my terminal (rxvt-unicode) working, so that when I ssh from Linux to macOS, the Home/End and other keys work properly. Usually, to accomplish this with a Linux remote host, I use a script like the following: ssh "$1" 'mkdir -p ~/.terminfo/r' for f in /usr/share/terminfo/r/rxvt-unicode{,-256color} do scp "$f" "$1":.terminfo/r/ done However, this isn't working with macOS. When I run screen, first I was getting "TERM too long - sorry.". After updating it to the brew version (4.06.02), I'm now getting "Cannot find terminfo entry for 'rxvt-unicode-256color'." TERM is correctly set to rxvt-unicode-256color, and ~/.terminfo/r/rxvt-unicode-256color exists. Running screen with TERMINFO=$HOME/.terminfo/ also has no effect.
ncurses uses 2-characters for filesystems (such as MacOS and OS/2) where filenames are case-preserving / case-insensitive. That is documented in the NEWS file. Apple, by the way, provides an old version of ncurses (5.7) which is still new enough for this feature. Portable applications should not rely upon any particular organization of the terminal database... By the way, current terminfo entries for xterm-256color will not work well with that old ncurses 5.7 base system, since the color pairs value exceeds limits. The effect upon rxvt-unicode depends on how the source was constructed. This is mentioned in the FAQ: ncurses 6.1 introduced support for large number capabilities, e.g., for more than 32767 color pairs. Other implementations generally treated out-of-range values as zero.
Why isn't screen on macOS picking up my ~/.terminfo?
1,448,250,142,000
Let's say we have opened more than 10 screens in the screen program. How to switch to a screen using Ctrl+A, n where n > 9?
There are three ways to do it CTRL + A + " will give you a graphical list of your windows that you can scroll around in. CTRL + A + ' will give you a prompt to type a screen number. CTRL + A + n (or p) will take you next window, let us say you are on window 9 and if you press this, it will take you to next (or previous) window
How to switch to a screen with two digit index in screen command?
1,448,250,142,000
So here's what happened: I ssh to the server with a normal user I run sudo -i I run screen Then I accidentally locked the screen session. to unlock it, it asks for root's password not the password of the normal user. The problem is I don't know the password of root. What can I do in this case?
You can attach to the session from "another terminal" (including another ssh connection). That lets you recover anything that was in progress. You can always kill the screen session as you started it, by using sudo to kill the parent process of the screen session (the one named "screen"). The feature only is useful if it is properly configured to begin with (usually that is not the case). Further reading: Disabling GNU Screen lock screen Can a locked gnu screen session terminal be accessed?
GNU screen locked, how to unlock?
1,448,250,142,000
I'm looking at replacing screen with tmux, currently I use this screen command: screen -d -m -S session_name /root/script Is there an equivalent command for tmux that will do the same thing?
The new-session command with the -d option is similar to the -d -m option in screen. The -s option corresponds to the -S option in screen. Note that -d and -s are options to the new-session command rather than to tmux itself. tmux new-session -d -s session_name '/root/script'
Tmux: equivalent command to screen -d -m -S session_name
1,448,250,142,000
Running a command in a screen and detaching is quite simple. screen -S test -d -m echo "output of command that runs forever" However I would also like to pipe all the output to a file for logging, how can run the following in a screen and detach. echo "output of command that runs forever" &> output.log Edit: Just to clarify, I need this for a script so simple starting a screen and doing running the command and detaching is not an option.
screen -dmS workspace; screen -S workspace -X stuff $'ps aux > output-x\n' I first create a detached session with the -d switch, I called my session workspace. I then send my command to the same session with -X stuff, I am using $'', but you could also use double quotes, but have to do a control M instead of a \n, which I don't like so I normally use the method I described above. After this piece of code runs, you will find the output-x with the list of processes, and also if you do a: screen -ls you will see the session has been detached. Since you said you are going to be running a script. You might want to have your script search for a detached session (I am using workspace), and if it exists send commands to that pre-existing session, instead of making a new session every time "screen -dmS sessionName" is ran, example is below: #!/bin/bash if ! ( screen -ls | grep workspace > /dev/null); then screen -dmS workspace; fi screen -S workspace -X stuff $'ps aux > output-x\n'
How to run a program in a screen, redirect all output to a file and detach
1,448,250,142,000
How do i get screen to execute/load .zprofile when starting a new window?
Put shell -zsh in your .screenrc, which will tell screen to start zsh as a login shell, which will in turn cause zsh to source ~/.zprofile .
How do i get screen to execute/load .zprofile when starting a new window?
1,448,250,142,000
Possible Duplicate: Shell: how to go to the beginning of line when you are inside a screen? Normally to get to the beginning of a line in a terminal the command is Ctrl+a. While using GNU screen the Ctrl+a is the escape sequence to enter a screen command. Is there a default way to move to the beginning of a line while in screen?
The sequence to send a literal C-a is explained in the man page: C-a a (meta) Send the command character (C-a) to window. See escape command. so you should use C-a a. So, if you have a screen inside the other (for example screen + ssh + screen) you should use that prescription multiple time, and in the case at hand it becomes C-a a a
Move to the beginning of a line in screen [duplicate]
1,448,250,142,000
Background I use virtualenv to switch between environments "1.0" and "2.0". I use screen to manage terminals. When I work on one environment I want all new screen windows to start with this environment. Question Can bash instruct screen to set environment variable on new shell instances, so I could make an alias similar to this one: alias one='export PRJCT=1.0; screen-magic-setenv PRJCT=1.0; workon 1.0' alias two='export PRJCT=2.0; screen-magic-setenv PRJCT=2.0; workon 2.0' and afterwards in ~/.bashrc call: [[ -z $PRJCT ]] || workon $PRJCT # switch to project if set I know I can command screen to set environment variable on new shells like below but it doesn't help as it won't work in an alias: :setenv PRJCT 2.0
If I understand correctly, your problem is you cannot find a way to use a shell alias to interact with screen directly. Instead, you can send commands to a running screen using -X, including setenv of course, e.g.: $ screen -list There are screens on: 25216.pts-45.antiriad (Attached) $ screen -S 25216 -X setenv PRJCT 2.0 The variable is then set, and will be inherited by child shells from that point on, exactly as with :setenv. If you use -S to set sensible distinct session names your task may be easier. The variable STY holds the current screen session. If you run just screen -X setenv PRJCT 2.0 within a screen session, omitting -S, it will apply to that screen instance. alias one='export PRJCT=1.0; screen -X setenv PRJCT 1.0; workon 1.0'
How to set `screen` environment variable from bash?
1,448,250,142,000
I added the following line to my .screenrc script such that I can use my mouse to scroll up and down in the terminal when the output is too large and long. However, when I try to source .screenrc script. It complains that termcapinfo command not found. termcapinfo xterm ti@:te@ I have no idea what went wrong ? Why is this happening ?
You should not source it. The file .screenrc is read and interpreted by screen at start up. Moreover please note that termcapinfo xterm ti@:te@ will work only if your terminal set $TERM variable to xterm. In other case termcapinfo xterm*|rxvt*|kterm*|Eterm* ti@:te@ is probably more universal solution. There is also possibility to scroll by keyboard shortcut Ctrl-a ESC and then use up-down arrows.
Terminal: termcapinfo command not found
1,316,014,897,000
I used to leave my byobu sessions detached on a server. I want to lock the session to prevent other users (root account) accessing my session. Is this possible?
GNU screen (one backend that byobu can use, along with tmux) has the lockscreen functionality. Have a look at the man page to see what it does. The default binding is C-a C-x. With regard to your trying to lock root out, it's rather pointless. What you can try is to find a locking program that let you set a password and hope that root doesn't know about it.
Lock a byobu session with password?
1,316,014,897,000
I'm using an aws ubuntu instance. I would like to create an alias/function to run some shortcuts, for example to activate a python virtual environnement in a screen. I've made this function for example: # Alias for jupyter notebook function start_jupyter() { cd my_path/lab_workspace/ # 1. cd into my workspace source labworkspaceenv/bin/activate # 2. activate my python virtualenv screen -S jupyter_lab # 3. start screen echo 'You are in screen for jupyter lab' # 4. print something jupyter lab # 5. start jupyter lab } Problem is, when I run the function with start_jupyter, this seems to stop after 3. the screen is created but then nothing is printed and jupyterlab is not started. What am I doing wrong?
The reason the function stopped is that you spawn an interactive screen session. You might want to do this instead: screen -dmS jupyter_lab jupyter lab This will create a detached screen session named jupyter_lab and execute the command there. As per the screen --help info: -dmS name Start as daemon: Screen session in detached mode. So, your function would be: # Alias for jupyter notebook function start_jupyter() { cd my_path/lab_workspace/ # 1. cd into my workspace source labworkspaceenv/bin/activate # 2. activate my python virtualenv screen -dmS jupyter_lab jupyter lab # 3. start screen }
Execute bash function to run screen
1,316,014,897,000
I am having trouble with screen. It keeps terminating every time I try to console into my routers. eric@pop-os:~$ screen /dev/ttyUSB0 [screen is terminating] eric@pop-os:~$ screen /dev/ttyUSB0 [screen is terminating] It only works as root or superuser.
Does your user account eric have the permission to use /dev/ttyUSB0? To find out, please run ls -l /dev/ttyUSB0. The output might look like this: $ ls -l /dev/ttyUSB0 crw-rw----+ 1 root dialout 166, 0 Jul 9 08:55 /dev/ttyUSB0 The characters at the left-most column are the file type and permissions information: The first character is c, indicating a character-based device. The last character is +, indicating that there is an Access Control List (ACL for short) on this device node, specifying further access rules. This is important, because it changes how the other permissions are interpreted. The characters 2-4 are a three-letter group rw- indicating permissions for the file owner, which is root as indicated in the third column. The second group of three letters (rw- again) would classically indicate permissions applicable to the group of users the file is assigned to. In this case, the group is dialout as indicated in the fourth column. But because this file has an ACL, the meaning is different: with an ACL in effect, it just indicates the highest permissions granted to a specific user or group that is not the file owner - but you cannot know which user or group it is. The third group of three letters (---) indicate access permissions for everyone else - if it's all dashes, it means no access is allowed. The last character is +, indicating that there is an Access Control List (ACL for short) on this device node, specifying further access rules. Lastly, the ACL can be viewed with getfacl /dev/ttyUSB0. The output might look something like this: $ getfacl /dev/ttyUSB0 getfacl: Removing leading '/' from absolute path names # file: dev/ttyUSB0 # owner: root # group: dialout user::rw- user:sddm:rw- group::rw- mask::rw- other::--- Basically, it repeats the traditional non-ACL file permissions and allows specifying extra permissions for any number of users and groups. In this case, there is an extra line user:sddm:rw- indicating both read and write access to user sddm, which is the user account the GUI login manager process sddm is currently running as. And there's also the group::rw- line that confirms that the classic dialout group has full read/write access to this file - this information was hidden from the classic ls -l output when an ACL was applied to this device node. The fact that an ACL grants permissions to sddm indicates that this OS is probably configured to automatically grant access to local serial ports if you log in locally using the GUI login dialog. The ACL would be automatically changed to match the logged-in user, and back to sddm when the user logs out. If such an ACL is not present, then your distribution might not use such an automatic permissions mechanism. The group name dialout is historical, because serial ports used to be used with modems. But if a device is assigned to a special group like this, it indicates the distribution is probably configured to manage access to serial ports using the dialout group. So in this example, you might want to add your user account to the dialout group. You'll need root/superuser access to do that: # usermod -a -G dialout eric New group memberships take effect at next login, so you'll need to log out and back again. Because the /dev filesystem is a virtual, RAM-based filesystem, all the device nodes are created from scratch every time the system boots. Because of this, trying to change the permissions of the actual device nodes would be futile; your changes would be forgotten when you shut down the system. Instead, the default permissions for the devices use specific groups, for the express purpose of allowing the administrators to use group memberships to grant specific users access to specific types of devices: using those groups as intended is probably the easiest way to solve your problem.
Screen keeps terminating when trying to console in to routers
1,316,014,897,000
I'm looking for a way to drop the mouse, forever and always. I got to a very comfortable point, where I don't use it for regular text editing, however, something's bothering me. When I work with the shell and I want to copy some prev output, I need to highlight + copy using the mouse. That sucks. I know about screen and 'Ctrl-A [', is cool, but I want to browse the scrollback in Vim, not in Screen's built-in interface. Is there a way for me to open the current shell output buffer into Vim and copy from it?
From within a Screen window, run screen -X hardcopy -h s vim s rm s hardcopy -h dumps the scrollback into a temporary file which you can then open in Vim if you like. If you script this you should use a proper temporary file name: #!/bin/sh scrollback_file=$(mktemp) screen -X hardcopy -h "$scrollback_file" vim -c 'call delete(@%)' "$scrollback_file" (Or you could just run your shell in Emacs or in Neovim.)
Is there a way to open screen's terminal scrollback buffer in vim?
1,316,014,897,000
This is my current .screenrc files which is mostly copied from the link in the code #First iteration 2014-09-06, not quite sure of stuff to add # got a fancy hardstatus line noted below hardstatus on hardstatus alwayslastline # hardstatus string "%w" # blagged this hardstatus like from https://bbs.archlinux.org/viewtopic.php?id=55618, not quite sure what it does hardstatus string '%{= kG}%{C}Screen: %{c}%{= kG}[%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{C} %d-%m %{W}%c %{g}]' I now want the session name to appear in it as well, and the one I have settled on is from this answer - https://superuser.com/questions/212392/how-to-include-screens-session-name-in-hardstatus/212520#212520 The solution runs along these line: hardstatus string '%H:%`' backtick 0 30 30 sh -c 'screen -ls | grep --color=no -o "$PPID[^[:space:]]*"' It is an area I am not familiar with and I wonder how the backtick command fits in it, ie whether it is a screen command at all.
You can check this or better you can check man page for screen which is a good reference and says: backtick id lifespan autorefresh cmd args... backtick id Program the backtick command with the numerical id id. The output of such a command is used for substitution of the "%`" string escape. The specified lifespan is the number of seconds the output is considered valid. After this time, the command is run again if a corresponding string escape is encountered. The autorefresh parameter triggers an automatic refresh for caption and hardstatus strings after the specified number of seconds. Only the last line of output is used for substitution. If both the lifespan and the autorefresh parameters are zero, the backtick program is expected to stay in the background and generate output once in a while. In this case, the command is executed right away and screen stores the last line of output. If a new line gets printed screen will automatically refresh the hardstatus or the captions. The second form of the command deletes the backtick command with the numerical id id. As per your example you can add: hardstatus string '%H:%1` | %2`' backtick 1 30 30 sh -c 'screen -ls | grep --color=no -o "$PPID[^[:space:]]*"' backtick 2 60 60 /usr/bin/uptime
How can I add the session name to my screen status display?
1,316,014,897,000
While using GNU Screen in copy mode, I sometimes want to abort in the middle and go back to the prompt. What command will exactly achieve that ?
I think you want to use the Esc key. At least, that is what I use to get out of copy mode in screen. There are many alternative strategies as well, including hitting q, or hitting the Return key twice.
Abort copy mode in Screen
1,316,014,897,000
With GNU screen (version 4), why is it that the following runs perfectly fine: $ screen -S some-name But if I try having a slash (/) in the session name, it gives me an error about multiuser support. $ screen -S some/name Must run suid root for multiuser support. If I try setting the session name from within the screen: $ screen C-a :sessionname some/name I get the following error: : bad session name 'some/name' So apparently a / is invalid character for a session name. Looking at the man page for screen, I see nothing about invalid or reserved characters for sessionname: ‘-S sessionname’ Set the name of the new session to sessionname. This option can be used to specify a meaningful name for the session in place of the default tty.host suffix. This name identifies the session for the screen -list and screen -r commands. This option is equivalent to the sessionname command (see Session Name). 8.5 Session Name — Command: sessionname [name] (none) Rename the current session. Note that for screen -list the name shows up with the process-id prepended. If the argument name is omitted, the name of this session is displayed. Caution: The $STY environment variable still reflects the old name. This may result in confusion. The default is constructed from the tty and host names. Also, unmatched ' and " in the session name complain about unmatched quotes which seems to be about syntax. E.g., :sessionname 'test"' gives test" as the name. And ^A, ^B, etc. yield control characters. What is the valid syntax or characters for a session name?
The purpose of assigning a name to a screen session with -S is so you can operate on that session (for example with screen -r ...) by specifying its name. Looking at the man page under the -r option: -r [pid.tty.host] -r sessionowner/[pid.tty.host] resumes a detached screen session. No other options (except com‐ binations with -d/-D) may be specified, though an optional prefix of [pid.]tty.host may be needed to distinguish between multiple detached screen sessions. The second form is used to connect to another user's screen session which runs in multiuser mode. This indicates that screen should look for sessions in another user's directory. This requires setuid-root. So a session name with a / character is interpreted as owner/name. (This could be documented better under the -S option.) You can do screen -S $USER/name which is equivalent to: screen -S name In some quick experiments with screen version 4.01.00, I haven't found any other special characters that are prohibited in session names. All the following: screen -S 'foo bar' screen -S 'foo"bar' screen -S "foo'bar" screen -S 'foo\bar' screen -S "foo'bar^Xbaz" worked correctly for me. In the last one, the ^X was actually a literal Ctrl-X character. screen -ls shows it literally; I had to do screen -ls | cat -A to see it. I was able to resume all these sessions by specifying their names: screen -dr 'foo bar' etc., and the value of $STY within each session was correct. (I don't recommend using control characters, for what I hope are obvious reasons.)
Valid screen session names
1,316,014,897,000
I'd like to export the content of a detached screen under linux. I tried those command: screen -x 2>&1 > temp screen -x > temp 2>&1 screen -x > temp But it's not working, It keeps reattaching to a session instead of exporting it in the "temp" file. Screen version: 4.00.03jw4 What do I do wrong?
You probably want to do something like: screen -p 0 -X hardcopy this generates a file hardcopy.0 with the content of the screen session. The argument to -p determines which session. The files are dumped in screens current working directory or to the directory set set with the hardcopydir command. Check the screen configuration file for hardcopydir (/etc/screenrc).
Export content of screen daemon to file
1,316,014,897,000
I recently needed to copy X amount of lines from a file, that I opened in vim and then paste them to another file opened in a different screen session (and different server). So on screen #1 I ran in vim: :15,20y and on screen #2 I tried to use p to paste the lines, but I couldn't because the register was empty (to be honest, I was expecting that but I just wanted to give it a try). I eventually worked my way around in order to get those lines to the right place, but I wonder if it is possible to copy-paste data between screen sessions.
You can use the copy/paste functionnality of the screen command: First off, you select the text to be copied on screen #1: C-a esc With the command above, you're in window edit mode and this allows you to copy text from the current window and its history into the paste buffer. You move arround with the arrows and select your text with space bar. Go into the screen #2 Paste it by typing: C-a ] For more references to screen command, consult the manpage: $ man screen
Is it possible to copy data from one screen session to another?
1,316,014,897,000
I have a script that runs a series of scripts numbered 001,002,003,004... etc down to 041 right now, will be more in the future - and these scripts them selves use some cursor control to print a progress bar and other status information and get the width and height of the terminal from tput cols and tput lines respectively. Without rewriting the sub-scripts, I would like to reserve one line at the bottom for overall status information for the outer script. I was curious if there was a way to set what tput replies for lines and cols. There must be a way because tmux achieves it. I was thinking there may be an environmental variable but the only change I can see that tmux makes when running env is setting the $TERM to screen. Any help would be greatly appreciated
The following will let you customize the number of lines and cols tput returns export LINES=1000 export COLUMNS=1000
How to set Cols and Lines for a Subprocess
1,316,014,897,000
What's the difference between screen -S <sessionname> and screen -t <name>? It seems that both assign a name to the newly created screen, which can be reattached using this name.
-t <name> sets the default title for newly created shells in your screen session. If you invoke screen -t MyShell then type Ctrl+a c Ctrl+a c Ctrl+a w, you will see them at the bottom of your terminal: 0$ MyShell 1-$ MyShell 2*$ MyShell You can change each title of shells by typing Ctrl+a A. -S <sessionname> sets the name of the screen session you create. You can see existing sesions in the system with -ls, then attach one of them using that session name by -r <sessionname>. This feature is usefull especially when you have to maintain multiple screen sessions simultaneously. $ screen -ls There are screens on: 23834.pts-4.myserver (06/01/15 12:38:11) (Detached) 23812.MySession (06/01/15 12:34:24) (Detached) 2 Sockets in /var/run/screen/S-yaegashi. $ screen -r MySession You can change the name of current session by typing Ctrl+a : then enter sessionname <newsessioname>.
screen: ‘-S sessionname’ vs. ‘-t name’
1,316,014,897,000
.screenrc: shell -${SHELL} caption always "%n(%t) %= %{b}@%H[%l] : %{r}%c:%s" termcapinfo xterm ti@:te@ termcap xterm 'AF=\E[3%dm:AB=\E[4%dm' terminfo xterm 'AF=\E[3%p1%dm:AB=\E[4%p1%dm' startup_message off screen -t server 0 rails s screen -t spork 1 bundle exec spork screen -t dev_log tail -f ./log/test.log Pressing Ctrl+C in any of the screen windows above destroys it. I would like to have subshell for every so if I press Ctrl+C than I just exit to that subshell. Right now I'm running screen and creating all windows above manually, renaming them and it works great. I can terminate any program on any window, do something else and run it again. What I want to achieve is to have that set-up to run with just one command.
I decided to create another related question How to keep Bash running after command execution? to just forget about big picture and focus on the main problem. Worked as intended and finally there were presented 3 ways to achieve the goal: workaround which was not bad portable (POSIX) simple and I choose to use 3rd one that way: ~/.run_screen: #!/bin/bash /bin/bash -i <<<"$*; exec </dev/tty" ~/.screenrc: screen -t server 1 ${HOME}/.run_screen rails s screen -t spork 2 ${HOME}/.run_screen bundle exec spork screen -t dev_log 3 ${HOME}/.run_screen tail -f ./log/development.log screen -t test_log 4 ${HOME}/.run_screen tail -f ./log/test.log screen -t bash 0
screenrc subshell for every window
1,316,014,897,000
I use GNU screen to run pine mail reader. I use external aspell to do spellchecking for the e-mails I sent. The problem is that when aspell finishes, pine restores the old content of the terminal, but the color is all wrong. The font becomes white instead of black, which looks very bad on the the gray background. After typing something for a while, pine redraws parts of the screen, and that looks ok, but initially it looks very hard to read. The problem does not exist when pine is run directly, not from within screen. I do not know how to begin the troubleshooting. Any ideas? Pine version: Alpine 2.00 (LRH 1167 2008-08-23) GNU screen version: Screen version 4.00.03 (FAU) 23-Oct-06 Update 11 Dec 2011: The problem also occurs in some cases when resuming composition with Ctrl+O (no aspell involed). The following do not help: Ctrl+L in pine to refesh screen, adding "altscreen on" in ~/.screenrc adding "bce on" or "bce off" in ~/.screenrc (I tried both, as I am not sure what the default is) Starting screen with TERM=xterm-256color screen
I think I have resolved it. phunehehe was right about trying to change the terminal type. However, "TERM=xterm-256color screen" does not work because the TERM variable only tells screen what kind of terminal screen is run in. It does not tell screen to emulate that particular terminal. So, the solution was to include term "screen-256color" in ~/.screenrc configuration file. This seemed to solve the problem, but.... Update 12 December 2011: Actually doing the above fixed the color problem, but created another problem: Delete key no longer works in pine. It turned out that the computer on which screen is running lacks "screen-256color" terminfo file, and since it cannot find it, it reverts to the basic vt100 terminal. After trying several term settings, I found that "xterm-color" has neither Delete-key nor color problem. I do not understand why or how it works.
GNU screen color and pine
1,316,014,897,000
I have a couple of questions regarding screen: When I type screen -r, I get the following: There are several suitable screens on: 25154.tracks (Detached) 29278.mywork (Detached) 29138.mywork (Detached) 30915.mywork (Detached) 20065.mywork (Detached) Type "screen [-d] -r [pid.]tty.host" to resume one of them. I'm not sure, but I believe most of these screens are old, since I haven't used screen in some time, and I just accidentally detached from one. With this, my questions are: Is there a way to resume the most recently detached screen? How do I "delete" older screen sessions? Is it possible to display the date and # of screens within each session? Is there a way to temporally associate aliases to the screens listed by screen -r to facilitate their choice? For example, it would be great if screen -r listed screens as follows: There are several suitable screens on: [1] 25154.tracks (Detached) [2] 29278.mywork (Detached) [3] 29138.mywork (Detached) [4] 30915.mywork (Detached) [5] 20065.mywork (Detached) Choose one to resume: And then I could just type 1,2,3,4 or 5 without having to type the full pid of the screen I want to resume. Is there anything that would do the trick?
Here's a script that should work for you. #!/bin/bash function chooser { echo echo "I found the following screen sessions: " echo pcount=0 # # find the session dir # sessdir=$( screen -ls | egrep 'Socket' | awk '{print $NF}' | sed -e 's/\.$//' ) # # enumerate existing sessions, and add them to the plist() array. # for screen in $( find $sessdir -type p ); do pcount=$((pcount+1)) pname=$( basename $screen ) pdate=$( ls -latr $screen | awk '{print "( "$6" "$7" "$8" )"}') plist[$pcount]=${pname} echo " [$pcount] $pname $pdate" done echo echo -n "Please select a session to reconnect to: " read choice # # if the selected choice doesn't exist, recycle the chooser. # if [ -z ${plist[$choice]} ]; then echo echo "Your choice [$choice] is invalid. Please try again." echo sleep 1 chooser else screen -r -d ${plist[$choice]} fi } # # the chooser function does all the work # chooser I didn't distinguish between sessions that are currently attached or detached, so you may have to do that yourself if it matters to you.
Screen: Resuming most recent screen? Making selection easier?
1,316,014,897,000
Protecting a GNU screen session with a password is good security. However, how does one remove the password if you need to share a session with a colleague? I tried the following to clear it and got locked out (I ought to have tested it before detaching, but...): ctrl+a :password clear So, what exactly is the password set to in the above scenario? Neither my previously set password nor my system account password would let me back in!
From man screen: password [crypted_pw] Present a crypted password in your ".screenrc" file and screen will ask for it, whenever someone attempts to resume a detached. This is useful if you have privileged programs running under screen and you want to protect your session from reattach attempts by another user masquerading as your uid (i.e. any superuser.) If no crypted password is specified, screen prompts twice for typing a password and places its encryption in the paste buffer. Default is `none', this disables password checking. ctrl+a :password none should do what you want.
GNU Screen - any way to remove password when detached?
1,316,014,897,000
I want to run streamripper in its own X Terminal (window), then split the terminal horizontally, and then run mplayer in the lower half. This is simple enough to do manually, but getting a script to do it eludes me. start a new terminal window run streamripper http://radio.net:8000 -r 8000 split the terminal window horizontally run mplayer http://localhost:8000 in the bottom panel. mplayer cannot be allowed to run immediately. It needs to wait for stream data, so a test for this would be better than "wait x seconds" (which is effectively what the manual method does. If the terminal is significant to this, anything will do, but I currently have installed konsole, gnome-terminal, and terminator (in Ubuntu)
Although some terminal programs have support for splitting, you won't be able to access this functionality from the shell which is running in a different layer and doesn't have access to the software displaying it. What you can do is use a terminal multiplexer such as GNU Screen or tmux that allow you to run multiple shells in "panes" inside a console. Screen has been around since the dawn of time and works, but lately the project has falled into dis-repair and it's not being well maintained. Tmux is kind of a new player on the scene but the code is very clean and mature, it has a few more features than screen, and it's a good deal easier to learn and configure. Even though I still use screen out of force of habit, I highly recomend you use tmux for this. You should be able to write a script that launches a tmux session, runs your streamripper code in one pane, waits for a condition, then adds another pane to the same session, displays it as a split screen, then runs mplayer in the new pane.
How to run streamripper and mplayer in a split-screen X terminal, via a single script
1,316,014,897,000
I use screen to connect to devices via RS232 with a USB-serial dongle. Currently, I use this command to invoke screen (where 115200 is my baud-rate): screen /dev/ttyUSB0 115200 Usually, I have more than one device (/dev/ttyUSB0 and /dev/ttyUSB1). Sometimes their baud-rate differs. Currently, I open a new terminal emulator and run screen for each instance, but that kind of defeats the purpose of screen. Can I access both devices in a single instance of screen? I'm thinking this would involve launching screen with no arguments and then attaching the session to a TTY with a specified baud-rate after it is created, but I don't see a command to change TTYs within a session. I know tmux can do that, but I'd rather stick with screen.
Once you've launched screen, you can use its internal screen command to attach windows to additional terminal devices. Type C-a: to get the prompt, then use screen /dev/ttyUSB1 ###### where ###### is this device's baud-rate. You can also put these commands in your .screenrc to attach the devices automatically when you start screen, or you could bind a keystroke to this command to get a shortcut. See the Window Types section of the screen manual.
Multiplex different TTYs with a single instance of screen
1,316,014,897,000
I have a virtual server, and a graphic application (an electron browser, actually) is running on it. I actually run the command launching it with this script: #!/usr/bin/env bash set -e # Start Xvfb Xvfb -ac -screen scrn 1280x800x24 :9.0 & export DISPLAY=:9.0 exec "$@" It's running even while I'm not connected to ssh, in a screen. However sometimes when connecting to the server I want to access its GUI. It's different from launching it directly with ssh -X. Is there any way to access the display created by Xfvb?
You can start a VNC server on an existing X server by using x11vnc. However, if you anticipate the need to do this, you may want to use Xvnc instead of Xvfb.
Access GUI of an already running application through SSH
1,316,014,897,000
I am using screen utility for couple of years. I just simply love it. In cloud machines I do have multiple screens as I work with a team. I want to log every commands that have been run in every sessions. Suppose there are three screens ex. A,B and C. I want to get A's all sessions commands and so on. It would be really great if you can give me a hint or details. Thanks in advance.
Set the deflog configuration parameter (in ~/.screenrc), then screen windows will be logged automatically. See info -f screen --index-search=deflog for details
How can I do logging of every screen sessions
1,316,014,897,000
I'm running Slackware GNU/Linux 14.2, which doesn't start an X server by default. On a whim, I tried running startx inside a screen session and got the warning /usr/libexec/Xorg.wrap: Only console users are allowed to run the X server xinit: giving up xinit: unable to connect to X server: Connection refused xinit: server error Couldn't get a file descriptor referring to the console Why can't I run startx from inside a screen session? What resource can you access on a "raw" console that you can't on a shell running under screen?
Running startx only makes sense if you are in front of the computer. Testing for console ownership is one way to determine this. As you have found out, it can be fooled by operating in a screen session. In that case, no X for you.
Can't run `startx` from inside screen session
1,316,014,897,000
I use screen with a simple status line. If I what to scroll, I use Ctrl+a ESC to enter the copy mode and then I can scroll using the keyboard. This works great also with multiple buffers and splits. My question is: How can I configure screen to use the mouse wheel to scroll? Note 1: Using the mouse wheel I can scroll inside my terminal, but this doesn't work with multiple buffers and splits at all. Note 2: The termcapinfo xterm* ti@:te@ solution doesn't help, since it uses the terminal scrolling. This is not compatible with status line, multiple buffers and splits. The best solution IMHO would be: In copy mode mouse wheel used for scrolling, like keyboard arrays do. If screen in the normal mode and the mouse wheel event "scroll up" comes in, screen switches to the copy mode and processes the event If screen in the copy mode and the mouse wheel event "scroll down" comes in, that hits the bottom, screen leaves the copy mode Screen status line is always visible and get refreshed (works already, if scrolling with keyboard)
screen does not know about the wheel-mouse. It only knows about keys (including escape-sequences) sent by the terminal and its keyboard: screen knows about mouse-clicks (its source-code mentions only "left mouse-click"). You can read the source-code (display.c) to see that it does no more than that (this, in particular, is the only place where screen decodes mouse-events). The xterm mouse-protocol will send buttons 4 and 5 to indicate the wheel-mouse. screen knows nothing about this; applications running in the terminal may handle it specially. Some terminals will send cursor-keys to imitate up/down scrolling when in the alternate-screen. screen (as expected) passes this on to the application as well.
Scrolling with mouse wheel inside screen
1,316,014,897,000
Screen uses the shortcut CtrlA to activate. I find that this interferes with the Bash command for jumping to the start of the line, and the VIM command for incrementing an integer. Certainly I could just remap it, but I am interested to know how other screen users deal with the situation. I don't think that I use CtrlQ for anything. What drawbacks and gotchas have other screen users encountered when changing the default shortcut? Note that I was unsure if Unix.SE or SuperUser would be more appropriate a place to post this. This could be a "chatty, open-ended question" or it could be a very useful resource for other screen users who undoubtedly encounter this, depending on how disciplined the answers are. I suspect that other screen users will more likely stumble across the question on Unix.SE. If SuperUser is a more appropriate place then any mod is welcomed to move it. Thanks!
Using CtrlQ is probably not a good idea unless you remap the start terminal key, for example, to CtrlX: stty start '^X' This is the complement of the stop character (CtrlS), which suspends output to the terminal from the OS. Myself, I've been using CtrlZ for over twenty years. I don't often suspend things since I can just create a new window, but if I do need to, then I just hit it twice.
Replacement shortcuts for `screen` [closed]
1,316,014,897,000
I'm managing with some boards like Arduino/UDOO etc. but I always face an annoying problem with minicom or screen. If i type a long command, for example: sudo /sbin/wpa_supplicant -s -B -P /run/wpa_supplicant.wlan0.pid -i wlan0 -D nl80211 -c /etc/wpa_supplicant.conf it reaches the end of terminal window, instead of continuing in a new line, it overwrites over the same line. One another annoying problem is when I up/down commands with UP/DOWN arrows. Check this gif while I up/down among last commands: This is my env: XDG_SESSION_ID=c1 TERM=linux SHELL=/bin/bash HUSHLOGIN=FALSE USER=udooer LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games MAIL=/var/mail/udooer LC_MESSAGES=POSIX PWD=/home/udooer LANG=en_US.UTF-8 NODE_PATH=/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript HOME=/home/udooer SHLVL=2 LANGUAGE=en_US.UTF-8 LOGNAME=udooer LESSOPEN=| /usr/bin/lesspipe %s XDG_RUNTIME_DIR=/run/user/1000 LESSCLOSE=/usr/bin/lesspipe %s %s _=/usr/bin/env checkwinsize is ON. Even nano is resized to a minipage in top-left of the bigger screen :/ How to solve it?
You need to manually execute stty cols ... rows ... and/or export LINES and COLUMNS to set the remote side's belief about the size to the terminal's actual size. Unfortunately there's no way this could be set automatically over a serial line.
Screen/Minicom multiline problem [duplicate]
1,316,014,897,000
xterm: $ echo $TERM xterm-256color $ stty -a speed 38400 baud; rows 52; columns 91; line = 0; intr = ^C; quit = ^\; erase = ^H; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0; -parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel iutf8 opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke gnome-terminal: $ echo $TERM xterm-256color $ stty -a speed 38400 baud; rows 57; columns 100; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = M-^?; eol2 = M-^?; swtch = M-^?; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0; -parenb -parodd -cmspar cs8 hupcl -cstopb cread -clocal -crtscts -ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc ixany imaxbel iutf8 opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke When outside tmux, Ctrl-v Ctrl-h outputs ^H. Inside tmux, I start getting ^? if run from xterm. Inside screen run from xterm it still outputs ^H. What's the reason behind this? Should it output ^H or ^?? How to remedy this?
The reason is that in your xterm, ^H is the erase character, and tmux apparently translates the erase character to the corresponding control character (^?) for the terminal it emulates, so that erasing works as expected in cooked mode (for instance, what happens when you just type cat). The translation is needed in case you use a terminal with ^? as the erase character (generated by the Backspace key), then resume the session with a terminal that uses ^H as the erase character (generated by the Backspace key). Unfortunately this has visible side effects in some cases, e.g. if you type Ctrl+H. The only good remedy is to make sure that all your terminals (real or in tmux) use the same erase character, which should be ^? (this is standard nowadays). It seems that your xterm is badly configured. This is not the default configuration, AFAIK. In any case, you need to make sure to use a TERM value for which kbs=\177. However this is not the case for xterm-256color from the official ncurses. So, you either need to select a different TERM value or you need to fix the kbs entry for xterm-256color (this can be done by the end user with: infocmp > file, modify file, then tic file). Some Linux distributions do not have this problem; for instance, Debian has fixed this problem via a debian/xterm.ti file in its ncurses source package, giving: $ infocmp xterm-256color | grep kbs kbs=\177, kcbt=\E[Z, kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, You should also have: $ appres XTerm | grep backarrowKeyIsErase: *backarrowKeyIsErase: true Note that you can do stty erase '^?' in xterm (before doing anything else), but this is just a workaround (and it may break the behavior of the Backspace key). You should actually have erase = ^? (as shown by stty -a) by default! In case problems with Backspace and/or Delete remain, I recommend the Consistent BackSpace and Delete Configuration document by Anne Baretta.
Why pressing Ctrl-h in xterm + tmux sends "^?"?
1,316,014,897,000
I'm running the sleep command in terminal using screen and in detached mode. Once the screen immediately returns, I'm running ps command to verify the sleep is running. $ screen -d -m 'sleep 2m' [raj@localhost ~]$ ps PID TTY TIME CMD 22795 pts/0 00:00:00 bash 22869 pts/0 00:00:00 ps But the command didn't show sleep. What is that I'm doing wrong here?
This was confusing to me initially as well. I then re-read the local screen man page for the SYNOPSIS -- the online man page does not give a synopsis) -- and noticed that it said: screen [ -options ] [ cmd [ args ] ] ... which led me to believe that it wanted to see the cmd and args as independent arguments. Since you gave that first argument as a quoted value -- 'sleep 2m' -- it tried to execute a command named (exactly) 'sleep 2m', as opposed to what you really wanted, which was sleep with its own argument of 2m. The screen command exited successfully (in my testing), but it did not successfully execute your command. Use, instead: screen -d -m sleep 2m Instead of ps, which will only show processes associated with the current terminal (of which the SCREEN and related processes are not), use: ps x which will show it: $ ps x PID TTY STAT TIME COMMAND # ... 7514 pts/1 Ss 0:00 -bash 7761 ? Ss 0:00 SCREEN -d -m sleep 2m 7762 pts/2 Ss+ 0:00 sleep 2m 7880 pts/1 R+ 0:00 ps x # ...
sleep command using screen command is not displayed in ps
1,316,014,897,000
Whenever I use ssh-agent for passwordless logins it doesn't work across different logins and screen sessions, even if they are concurrent. I suspect it uses some shell variables that don't work across different sessions. Is there some way to configure it or get it to use some kind of variables that can be present on all sessions?
I use keychain to manage my ssh-agent environment variables, and it deals with making sure only one agent is running at a time. From my .bashrc on appropriate machines: # is this an interactive shell? if [[ $- == *i* ]]; then # set up ssh key server if [[ -x /usr/bin/keychain ]]; then eval $(keychain --eval --ignore-missing the <keys I want>) fi fi It stores the environment variables in ~/.keychain, runs the agent if it isn't found, and returns the new or existing variables to the eval. I set it up a few years ago and haven't touched it. If you have ssh-askpass installed, it will be able to prompt for the password in an X11 environment even when the shell running keychain isn't visible (such as X11 init scripts). There are other ways to use it, but this works for me across multiple Linux workstations, including logging into a workstation from remote when I'm not logged into X11 there.
Is there a way to maintain ssh-agent connectivity in different screens?
1,316,014,897,000
I was unable to resume my screen session this morning, even after I killed the old screen -r session. svtbuild@dvm-2:~/rfs$ screen -r 17757.pts-0.dvm-2 There is a screen on: 17757.pts-0.dvm-2 (11/27/2012 04:49:19 PM) (Attached) There is no screen to be resumed matching 17757.pts-0.dvm-2. After waiting for a while I was able to resume. How can I do this more reliably?
From the screen manpage: screen -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. As mentioned for the options -D -RR, unless you know the status of your session(s), you should check it with screen -list.
GNU screen: how to resume my screen session reliably?
1,316,014,897,000
I found: GNU Screen window rename nuisance However, none of the answers there solve my problem and my situation is slightly different from the linked question. I work in a large infrastructure where I might log into any of hundreds of hosts in a given day. I don't have the authority to manage the default PROMPT_COMMAND on all of these servers. I've read through the man page section about naming windows (LESS='+/^TITLES' man screen) and I don't see any solution therein to my problem. How can I cause my windows in screen to KEEP the titles I set (with Ctrl-A A) regardless of the settings on servers I log into from my screen session? (Example use case: I might have a window titled "db-hosts" where I can log into a random sampling of DB hosts to check them, logging out from any given one when I am done checking it and logging into a different one.)
The bug report I posted was answered almost immediately with a comment that this feature was added in a newer version of screen: Since v.4.5.0 there is defdynamictitle [on|off] for global setting and dynamictitle [on|off] for per window settings.
Turn off GNU screen dynamic window titling for entire screen session
1,316,014,897,000
I'm using screen terminal multiplexer. For some reason a dashed line appears on the 10th row. ... [ec2-user@ip-172-31-1-24 var]$ ls account db games lib lock mail opt run tmp yp cache empty kerberos local log nis preserve spool www [ec2-user@ip-172-31-1-24 var]$ ---------------------------------------------------------------------------- ... My available work area was limited to a few lines. What does this means, and how can I recover the entire workspace?
I'd like to present another answer that might help other users who come across this: On GNU Screen by default, the dashed line means something else than what @slm said. His answer was covering tmux. For screen splitting (CTRL + A + S) in screen, the line is made out of solid full block characters. (█) The dashed line on screen is being used to show the window borders of the display/terminal which first attached the screen session. I'll give an example: You have a 1280x1024px monitor on which you start a screen session on a fullscreen terminal. Now on another machine, with a 1920x1200px monitor and a fullscreen terminal, you execute screen -x <session>, entering multi-display mode. On that terminal you will now see dashed-lines the size of your first terminal, and you won't be able to use more space until you detach (-d) the screen from the other terminal. This is to ensure that every attached terminal always sees all the contents.
what does the dashed line on a `screen` multiplexed terminal?
1,316,014,897,000
I want to SSH into a server, start a screen session, cd into path/to/my/script/, and run test.sh there. As a starter, I tried ssh [email protected] screen -dm bash -c 'cd path/to/my/script/; pwd > ~/output.txt' and expected to see path/to/my/script/ in output.txt, but I see my home directory there. This means the cd command doesn't really work, so bash won't be able to run test.sh. How may I solve this?
The short answer: add some extra quotes around the command, like this: ssh [email protected] "screen -dm bash -c 'cd path/to/my/script/; pwd > ~/output.txt'" To see what's going on, you can specify the -v option to ssh to obtain some debug information. In this case, you'll see a line like the following for the original command debug1: Sending command: screen -dm bash -c cd path/to/my/script/; pwd > ~/output.txt while the extra quotes change this into debug1: Sending command: screen -dm bash -c 'cd path/to/my/script/; pwd > ~/output.txt' So it appears that ssh just takes the arguments that were passed to it, concatenates them all, and lets the remote side split the concatenated argument list again into individual arguments. Calling the argument list argv (like in C), you've got something like the following in the original version: argv[0] = ssh argv[1] = [email protected] argv[2] = screen argv[3] = -dm argv[4] = bash argv[5] = -c argv[6] = cd path/to/my/script/; pwd > ~/output.txt Now in principle, it would have been possible for ssh to pass argv[2] to argv[6] as separate arguments to the other side, in which case it would probably have worked as expected. But as the debug line shows (and it also seems like this based on the source code), these arguments are concatenated to the string screen -dm bash -c cd path/to/my/script/; pwd > ~/output.txt which is then interpreted at the remote end. From this it's also clear why it doesn't do what you'd like: now you're executing two things in sequence, first screen -dm bash -c cd path/to/my/script/ (so a screen session is started in which only the directory is changed) is executed from the home directory, and then pwd > ~/output.txt is executed, also from the home directory. For completeness, the arguments for the command with the double quotes are argv[0] = ssh argv[1] = [email protected] argv[2] = screen -dm bash -c 'cd path/to/my/script/; pwd > ~/output.txt' causing screen -dm bash -c 'cd path/to/my/script/; pwd > ~/output.txt' to be sent to the other side (as shown by the debug line), which does work as intended.
SSH into server, start screen session, change directory?
1,316,014,897,000
After starting multiple gnu screen sessions with screen -S name1 screen -S name2 I would like to selectively attach to them. If I do screen -D -R name1 it will not attach but instead print: There are several suitable screens on: 6799.name1 (08.02.2013 15:47:23) (Detached) 3661.name2 (08.02.2013 13:43:25) (Detached) Type "screen [-d] -r [pid.]tty.host" to resume one of them. It works obviously if I type: screen -D -R 6799.name1 But I would like to attach without knowing the tty number, because I want to start the screen sessions by a script which takes the name as argument. Not knowing the tty number at this time I would need to copy by hand this number whenever I want to reattach later. An obvious solution would be to extract the tty number from the above screen output using string operations. But that seems a little awkward. Is there a way to tell screen to attach to a specific named session, whatever the tty number is? Note that I tried the different [-d|-D] [-r|-R] combinations mentioned in the man pages. Note added: I create the separate screen sessions in a script using ssh with ssh -t ${host} " screen -S \"$exefile\" -t \"$exefile\" -R "nice -n$prio \"$exefile\" ${exeparams[@]}"; exit 0"; Later I try to connect using ssh -t ${host} " screen -D -R -S \"$exefile\" && echo \"finished.\"; exit"; where $exefile is the name of the executable and the screen session I want to connect to.
The only reliable solution I found was the brute force method outlined in the question. To connect to an existing screen with name $exefile on remote $host via ssh, or to create a new one if it does not exist, one may use (in a bash shell): ssh -t $host " echo \"done.\" && echo \"itentifying screen ...\" && myscreen=\`screen -list | sed -n \"s/^\\s*\\s\\([0-9]*\\.$exefile\\)\\s\\s*.*$/\\1/p\"\` && if [ "X\$myscreen" = "X" ]; then echo \"no existing screen session found, creating new\"; screen -S \"$exefile\"; else echo \"connecting to screen \$myscreen\"; screen -d -r \"\$myscreen\"; fi && echo \"finished.\"; exit"; The first run will create a new session on $host. If the screen is detached with Ctrl+a,d the ssh login shell closes. If the same command is issued again it will reconnect to the existing screen. Multiple screen sessions with different names $exefile are possible and can be reattached independently. The magic is done by sed which searches the output of screen -list for a name matching the pattern [tty].name. Note that the screen name might need to be escaped if it contains sed special characters.
How to attach gnu screen without knowing tty number
1,316,014,897,000
So I have a screen session running on one terminal/machine I would like to write a script that would attach to that screen session on another machine, but to a new window in that screen. Does anyone know how I can do this? I feel like it might have somethig to do with screen -x (session name) -p (window number)...if i put "-" as the window number, it goes to a blank screen, but I want a fresh window. EDIT: Not really looking for a solution anymore myself, a neat tool called "tmux" replaces screen and makes this all trivial.
Here is the answer: https://stackoverflow.com/questions/10599769/attach-to-screen-session-with-creating-a-new-screen-window I was looking for the same thing
Attach to existing screen session, but new window
1,316,014,897,000
Is it normal, that when I am logged in as root, and the used su user, I can't access that users screen sessions? In this case, screen complains about it not having permissions on /dev/pts/x. I assume that it can't control the terminal which was opened as root in the way it needs: am I right?
In general, you can change the ownership of /dev/pts/x to the user that you su to, as root, before you actually su. That way, the user that you su to will have access to attach the screen to your origin terminal. # chown someuser /dev/pts/x # su - someuser $ screen -dr somescreen If this is something you want to make more smooth, you could look into how ownership is set on terminal devices, so that you could, say, make them group read/writable, and have a small group where users have access. This can have severe security implications, so do take care if you're exploring that path!
GNU Screen does not work when su'ing from root to a normal user
1,316,014,897,000
I'm using GNU screen and I want to save input from stdin into a register to slowpaste it later. I tried a workaround with a temp file (which I can read into a register with readreg afterwards) and to use cat: :eval "exec | sh -c 'cat >/tmp/screentempfile'" However, if I press CTRLD to send EOF to cat, it doesn't arrive.
That should rather be: :exec ... sh -c 'cat > ~/.screen-paste' You need stdin of cat to be coming from screen, hence the first .. The command shouldn't output anything, so the two other fds don't matter much, though it makes sense for them to go to screen as well, hence the two other .s.
In GNU screen, how to read from stdin and save into a register?
1,500,100,452,000
I often have to login into Linux devboards with known fixed usernames and password via the serial port. The normal commands are: screen /dev/ttyS0 115200 and then inside screen the session looks like: <enter> somehost login: root<enter> Password: root<enter> user@host# How to automate this login procedure so I don't have to type the username and password every time? I can also use expect if needed. I've tried: expect -c "spawn screen /dev/ttyS${1:-0} ${2:-115200}; send "\r"; expect \"* login: \"; send \"root\"; expect \"Password: \"; send \"root\"; interact" but my expect skills don't quite cut it and this just hangs. Also, if I logoug and login immediately, the second time it does not ask for the password and goes directly to the prompt: user@host# so hopefully the script should also take that into account. See also: https://stackoverflow.com/questions/9464887/modify-expect-based-ssh-script-to-work-on-machines-that-dont-require-a-password Similar question for SSH: https://stackoverflow.com/questions/459182/using-expect-to-pass-a-password-to-ssh
You can help to debug expect by adding option -d. In your example you would see that you are doing "...send "\r"..." which is evaluated by the shell as ...send r... because \r is on its own outside the doublequotes. Try changing that to send \"\r\" as in the other cases. You also need to put a similar carriage-return at the end of each send: send \"root\r\". It would cleaner to write a small shell script file, or use single quotes, converting to doublequotes for the ${1:-0} that need interpolating: expect -c 'spawn screen /dev/ttyS'"${1:-0} ${2:-115200}"'; send \r; expect " login: ";...' This complete script (without using the shell) also deals with the already logged in case: #!/bin/expect -- set tty 0 set baud 115200 if { $argc >= 1 } { set tty [lindex $argv 0] } if { $argc >= 2 } { set baud [lindex $argv 1] } spawn screen /dev/ttyS$tty $baud send \r expect { "login: " { send root\r expect "Password: " send root\r } "#" } interact
How to send keystrokes before interactive shell to automate Linux serial port login with GNU screen?
1,500,100,452,000
The "screen" window manager allows specifying the desired size of the scrollback buffer. E.g. when starting a new session: (source) ‘-h num’ Set the history scrollback buffer to be num lines high. Equivalent to the defscrollback command (see Copy). Or when already inside a screen session with these commands: (source) 12.1.2 Scrollback — Command: defscrollback num Same as the scrollback command except that the default setting for new windows is changed. Defaults to 100. — Command: scrollback num Set the size of the scrollback buffer for the current window to num lines. The default scrollback is 100 lines. Use C-a i to view the current setting. But I cannot seem to find documentation stating the maximum value for num for any of above approaches. So the question is: how to determine the maximum scrollback length for the screen utility?
I'm not sure where to find it documented, but digging into the source a bit gives some clues. When you pass in -h it sets the histheight (see screen.c). In main it parses -h as follows: case 'h': if (--argc == 0) exit_with_usage(myname, NULL, NULL); nwin_options.histheight = atoi(*++argv); if (nwin_options.histheight < 0) exit_with_usage(myname, "-h: %s: negative scrollback size?", *argv); break; The nwin_options struct is an instance of NewWindow which is defined in window.h: struct NewWindow { int StartAt; /* where to start the search for the slot */ char *aka; /* aka string */ char **args; /* argv vector */ char *dir; /* directory for chdir */ char *term; /* TERM to be set instead of "screen" */ bool aflag; bool dynamicaka; int flowflag; int lflag; int histheight; int monitor; int wlock; /* default writelock setting */ int silence; bool wrap; bool Lflag; /* logging */ int slow; /* inter character milliseconds */ int gr; bool c1; int bce; int encoding; char *hstatus; char *charset; int poll_zombie_timeout; }; where we can see that histheight is an int, so presumably the max value you can set it to is maxint for a signed int.
maximum scrollback size of "screen" window manager
1,500,100,452,000
login to Server1 and run screen SSH to Server2 and connect to an existing screen session Realise ^A commands are procesed by Server1's screen only Is it possible to control Server2's screen in this situation? Even if only to detatch from it. The only thing I could see to do was tell Server1's screen to kill its window containing the SSH session.
Yes, it is possible. One of the commands you can send Screen with its metacharacter (^A) is a literal ^A, which is done with the ^A-a (ctrl-A, lowercase a) sequence. On the help screen (^A-?), you will see one key defined as meta. So, in short, to send a command to a screen within a screen (e. g. to disconnect the nested screen), you would press ^A-a-d, which would send ^A-d to the nested screen, detaching it and leaving the first-layer screen connected.
Send commands to screen within screen
1,500,100,452,000
Question How do I find out the default directory of a window in GNU screen? NB: I’m not looking for the current directory of the process running in the window. Background I have created a hardcopy of my scrollback buffer without giving an absolute path. Now I don’t know where to find the created file. I don’t remeber from which directory I have originally invoked screen and I haven’t used any chdir command. I’m now wondering which directory I have polluted with my hardcopy … :-\
The easiest is probably to just make a new window, it will start in the directory where screen was started by default. Alternatives include looking at the process' cwd (e.g. /proc/<pid>/cwd, but this requires root as screen is setuid) Note that you can change that directory with C-a :chdir <path> later
How to Find out a GNU Screen Window’s Default Directory?
1,500,100,452,000
My ssh connection is unreliable, so I've been studiously using screen and detaching every time I start a long-running process. The screen part I know is necessary, but is the detaching as well? Thanks.
You do not have to disconnect, if the connection gets interrupted you can use screen -dr to reattach to a already running screen session that wasn't properly disconnected from first. Simply list out the screen sessions using screen -ls: $ screen -ls There is a screen on: 10266.somesession (Attached) 1 Socket in /var/run/screen/S-slm. Note the sessions name, 10266.somesession and reattach to it like so: $ screen -dr 10266.somesession NOTE: So long as the other system where screen is running is not rebooted or the parent process that owns screen is not killed, your screen sessions will remain intact.
Does the screen need to be detached to keep the process running after disconnection
1,500,100,452,000
Let us say I run screen -R myscreen. Then, I run commands on myscreen that are bigger than my monitor size so I end up loosing the visibility of the first commands I run. Then, I do Ctrl+d to leave the screen. Now I want to see all the commands I ran in myscreen. How would I do that? How would I see all the history in myscreen? If I do screen -R myscreen I am attaching myscreen but I can only see the latest commands but they are truncated by the size of my actual monitor and I don't know how to navigate up...
Screen maintains its own scroll back buffer. You can access it like so: Ctrl+a+Esc You can then use the arrow keys to move up and down through this scroll back buffer. When done hit Esc again to get out of it.
see all commands/logs of screen in linux
1,500,100,452,000
I am connecting to an embedded Linux board using screen over a serial link and trying to change the terminal type, as the default vt100 is pretty restrictive in terms of colours and scrolling etc. The screen manual suggests the configuration option termcapinfo but using that doesn't fix the issue. On the host machine, TERM is set to xterm-256color and when I connect to the target, using the termcapinfo setting in my .screenrc, TERM is still set to vt100. I am thinking maybe I should set something on the target machine?
It's the remote machine that sets $TERM to vt100, because it cannot know what terminal emulator your connecting with. vt100 is a safe value as the majority of modern terminals and terminal emulators (including screen) are compatible. To tell the applications over there what your terminal actually is, you have to set $TERM explicitely: TERM=screen You can do: find $(infocmp -D) -printf '%f\n' | sort -u | grep screen to see if there are more appropriate entries like screen-256color.
Change terminal type for screen over a serial connection
1,500,100,452,000
I often use only two applications, terminal and web browser. I like the tmux application which enables to split a terminal window into more regions. I noticed that I can open lynx in another region and have a browser and terminal displayed at the same time. But command-line browsers aren't very nice for viewing web pages. Konqueror is able to split a web page into more regions. It would be great if there was a browser which could display a web page in one region and a terminal in another region. Is there already a program combining web browser and terminal?
The job of splitting the screen into regions is normally devoted to the window manager. Many window managers have facilities to quickly set up or recall a window arrangement. If you find that you divide your screen between unobscured windows often, you may want to switch to a tiling window manager. Choosing a tiling WM has already been discussed on this site: Need advice in choosing a tiling WM; Tiling windows in GNOME.
Terminal and web browser combination
1,500,100,452,000
I auto start gnu screen when I ssh into one on my own servers. When I am done, I have to d to detach. Then exit to quit ssh. This means that when I ssh into the server again at some point in time, I can continue where I left off. Can I create a alias (for instance) that will (from within screen) detach and drop ssh?
Starting screen when logging in on the remote host (executed on your local machine): ssh -t user@host screen In the screen session, on the remote host, to detach and log out (which would end the SSH session unless you are using a persistent connection using a control socket (i.e. using the ControlMaster setting with ControlPersist in ~/.ssh/config)): screen -d Later, to log in and re-attach: ssh -t user@host screen -r Note that you have to use -t with ssh, forcing pseudo-terminal allocation, to start screen in this way. The alias on the remote host would be for screen -d, maybe detach='screen -d' or something similar. On the local host, you could have a section in your ~/.ssh/config file saying Host *-screen RequestTTY force RemoteCommand screen -d -R Host myhost myhost-screen HostName myhost.somedomain.example.com User myname Then, whenever you use ssh myhost-screen a screen session would be created (or re-attached to) on the specified host, while ssh myhost would not use screen. Note: RemoteCommand was added in OpenSSH 7.6 (2017-10-03). For tmux: Use tmux new-session -A -s "%n" in ~/.ssh/config instead of screen -d -R. Use prefixd or tmux detach-client or tmux detach to detach.
alias to detach screen when I exit (and kill ssh)
1,500,100,452,000
I have recently started using screen in order to be able to split my terminal vertically and horizontally. However, it does not clear the terminal automatically. For example, when I open a file using vim and then I close it, the screen fills the terminal with the content of file. Is there a way to fix it and make it like normal Terminal?
You're probably thinking of the alternate screen feature, which allows full-screen applications such as htop to display in a different view, and on completion returning to the normal view (without the application showing). That is the altscreen setting in your .screenrc, described in the manual: Command: altscreen state If set to on, "alternate screen" support is enabled in virtual terminals, just like in xterm. Initial setting is ‘off’.
How to force `screen` to clear the terminal after commands like `htop`
1,500,100,452,000
Whenever I try to start a screen-session as a non-root-user I get "No more PTYs." as a response. Same command in the same directory as root works properly. I tried the solution from this post but it won´t change anything: $ ls /dev/pts $ cat /proc/sys/kernel/pty/nr 0 $ cat /proc/sys/kernel/pty/max 4096 Even unmounting and remounting doesn´t help: $ grep /dev/pts /proc/mounts devpts /dev/pts devpts rw,nosuid,noexec,relatime 0 0 $ umount devpts $ mount devpts /dev/pts -t devpts -o mode=620 Related question of mine: Starting a minecraft server using screen doesn´t work properly
Very likely you cannot make screen use the BSD pseudo terminals because it is compiled to use a specific style of pseudo terminal (never both). There are two main flavors with variations: a function (such as openpty) provides the names for the master and slave devices the program searches through a list of master/slave pairs for an unused pair In the latter case, you could do a strings /usr/bin/screen and find something like this: 0123456789abcdef (perhaps longer). If you do not find that, it is compiled for Unix98 pseudo terminals. If you do find the string, it is possible that screen has to run setuid'd, e.g., to root (so that it can modify the permissions and ownership of the master/slave pairs). Since the question implies that it works running as root, it is likely to work for ordinary users after something like sudo chmod u+s /usr/bin/screen
"No more PTYs" when starting screen as non root-user
1,500,100,452,000
How can I derive the character sequence that represents a certain keystroke in screen? I mean, what bind takes as input. For instance, 's' represents the obvious keystroke on the 's' key. 'S' represents 'shift+s'. But the representation of other more complex combinations are unclear to me and the scheme that is followed seems quite obscure. I have searched all around and asked before what the representation would be for the particular case 'tab' and 'shift+tab', but I couldn't find the answer. So I guess the best is to try to understand the general scheme. I have also seen this, but it's now working for me. Can someone explain what scheme/rules screen follows for this? What are the rules to derive the representation of any arbitrary key combination? And are they screen specific, or shared with other software? Other GNU software maybe? Where is this documented?
There is no scheme, screen, like any terminal application, doesn't deal with keystrokes, but with characters or sequences of characters which it reads from a terminal device. It's the terminal (or terminal emulator like xterm) that transforms a keystroke into a character or sequence of characters which it sends over a wire (the wire being virtual in the case of a terminal emulator) to the system. The line discipline of the terminal device may do some modification on that (for instance, CRs turned into LFs). To know what character or character sequence screen receives when you type something on your terminal, you can use for instance od to display them for you. For instance, if I enter od -tc in a terminal, od -tc will read characters from the terminal device, and display them on stdout (the terminal device as well if you've not redirected the output) in a printable way. For instance, here's the output when I type: Up Enter Ctrl+D (the latter to signify od the end of input): 0000000 033 [ A \n 0000004 Up has sent the 3 characters ESC, [ and A, and the \r has been changed to a \n. screen will actually set its host terminal in raw mode so that no transformation is done by the line discipline and no characters are treated specially (like the 004 character sent upon Ctrl+D above for instance). To see what the terminal sends in that mode, you'd do: $ stty raw; stty min 1 time 10; dd count=1 2> /dev/null | od -tc; stty sane 0000000 033 [ A 0000003 Notice how the \n output by od has not been converted to \r\n for output (\n is line-feed, when output to a terminal, it only moved the cursor down, not to the beginning of the line for which your need a carriage return (\r)). Above, we're setting the terminal in raw mode, but also set it so that a read on the terminal device times out after 10 hundredths of second as soon as 1 character has been received (because otherwise, we'd have to type a lot of characters before the read done by od returns). Pressing Tab on all terminals sends the TAB ASCII character also known as \t or ^I or C-I or \011. For Shift+Tab, not all terminals send the same thing (some send ESC [ Z, some send \t as well and some send nothing for instance). The terminfo database can tell you what that character is for a given terminal (based on the $TERM variable) via the kcbt capability (back tab, not necessarily sent upon Shift-Tab though). For the current terminal: $ tput kcbt | od -tc 0000000 033 [ Z 0000003
What is the scheme for textual representation of keystrokes in screen?
1,500,100,452,000
I'd like to write some scripts that would open multiple terminal panes in a single window, much like tmux or screen. I personally am well versed in tmux, and have used it for years, but other developers on our team don't want to know anything about it or other screen multiplexers. To this end, I'd like to write scripts that can section themselves off in multiple panes in a single window. Is this possible with straight up bash? My goals are to avoid requiring node or something that needs to be installed, (like blessed-contrib), to keep the process as simple as possible. write it using something preinstalled on most distros, and posix compatible. have a single terminal window that gets broken up into panes, where each pane could be a running process or command prompt. when someone hits ctrl+c it exits all panes, and returns to a single terminal.
I think it is safe to say that this can't be done purely with bash alone. You will either need a higher programming language like perl/python, or to control an instance of tmux with a script. Here's a quick review of the technology involved: In order to run a program in the terminal environment that it expects, you need to create a pseudo-terminal (pty) to host it. ptys are created and controlled using syscalls like ioctl, and have a rather low-level API. To do something like tmux, you would need to read the controlling-side of each pty constantly and then splice together those pieces onto the main program's terminal, using special terminal escape codes Terminal capabilities (i.e. the escape sequences supported by a terminal for cursor positioning and bold/color/underline etc) have hundreds of variations, so if you want any sort of compatibility you'll want to use a library like ncurses to help you set up sub-windows. There are some tools that let bash call ioctl but I don't think it can handle all the calls needed for pty allocation, and it isn't a standard tool anyway. You might be able to get around that by manually creating pty device nodes but you'd need to run as root and it would be a mess. bash can find out various terminal escape sequences from the tput command, and you can in fact write bash scripts that render windows of text, but without ncurses this is hard to do correctly and cross-platform and will take a ton of your time. In short, I don't think you can pull this off with plain bash and posix tools. Perl is installed on almost all unixes, and perl can make ioctl calls, so yes it should be possible to write this in perl even without installing any extra modules. However, again I expect it would take too long without at least using some extra helper modules like IO::Pty and Curses. But even with all this, there's a lot of work to do. I think your best bet is to try scripting tmux. I've not done it before, but that post gives the appearance of a few-days project instead of a few-weeks-and-tons-of-learning project. If your main objection is having to install tmux, you might try downloading and compiling a static binary of tmux, then distribute that with your script. A static binary avoids dependence on any library in the system, and should work on any modern Linux kernel of the right architecture. You could even compile binaries for multiple architectures and then have the script detect which binary to use.
How to write scripts that create multiple terminal panes, like tmux?
1,500,100,452,000
I use run my programm under gnu-screen with enabled logging to a file (log on / logfile options in .screenrc). But after some time the log file became too big. Is there some way to limit size of a log file?
Unless you want real-time control over the size of the log, you can use logrotate with cron to accomplish this. Assuming you want to rotate screenlog.log in your /home/username/ directory, you would create something like this configuration file: screenlog-rotate.conf: /home/username/screenlog.log { size 100k } then either run logrotate /home/username/screenlog-rotate.conf or set it up as a cron job to be run periodically. Keep in mind logrotate needs to be run as root by default and the configuration file (screenlog-rotate.conf above) needs to also be chowned to root, otherwise it will complain the permissions on the configuration are wrong. Test by running logrotate with the -v flag to see if it understood what you meant. The above configuration file is simple and will not keep old log files. It will just remove the file if it's over the size given, while screen still outputs its log as usual (I tested this). If you want the old logs to be kept, then you need to add rotate N where N is how many rotated logs you want to keep. Check out man 8 logrotate for details on how to configure logrotate. Here's a related question: How to limit log file size using >> logrotate seems to be included by default in Arch Linux, but I'm not sure of other distributions. I'd expect at least Debian to have it installed by default and it should be easy to install using a package manager.
How to limit screen's log file size
1,500,100,452,000
Overview I use Screen as an add-on to the Linux console so that I can have multiple screens and can run my server while doing additional tasks simultaneously. Issue The console output seems to be cut off if it gets beyond 25 lines, which is extremely irritating when an error is being thrown. Example As you can see in this picture below, there is much more space to be taken up in the console, but all of it is truncated. Note: On my main screen (the default screen for the console without adding any additional screen) I'm able to get the entire console to be filled up with text, which allows me to track my errors.
screen by default will use sizes which were current when screen was started. You can use ctrl-a F to resize to current terminal size. You can also use ctrl-a [ and arrow keys to scroll back in history.
How to stop Linux console output from being truncated when using Screen?
1,500,100,452,000
In screen there is a kill command, which kills the current window. This command can be sent even to a detached screen session by running: screen -S SessionName -X kill This works to kill the current window only. To kill any other window, it appears the only way is to first switch to that window and then kill it. The select command allows switching between windows in a screen session. Typing the following while attached to a screen session will select the window named foo. ^A:select foo However, when not attached to the session, it appears the select command has no effect. Running the following two commands will kill the current window, rather than the window named foo (unless of course that is the active window). screen -S SessionName -X select foo screen -S SessionName -X kill I have verified that this occurs even if I attach and detach from the session before attempting to select a window (a known workaround for some other screen quirks).
You can try -p to select the window, numbered from 0, eg screen -S SessionName -p 1 -X kill
Select screen in detached screen session [duplicate]
1,500,100,452,000
I use the screen command on several servers, where I monitor several log files. I arrange the log files to my preferences with several splits and by naming the regions. Sometimes the server gets rebooted or I have to log out from the screen session for various reasons, and it is tedious to set the this up manually every time. Is there a way to script this somehow, so that screen opens up with e.g. three split regions initially with specific names and executes a command in each region?
use ~/.screenrc on the server. example: split screen -t top top focus screen -t shell where: split — splits current window/region horizontally focus — switch to next region screen -t name [command] — set name for current window/region and run command
Screen: can I execute commands and split the window when starting screen?
1,500,100,452,000
tmux I followed Getting 256 colors to work in tmux: I have alias tmux='TERM=xterm-256color tmux' in ~/.bashrc and also set-option -g default-terminal "screen-256color" in ~/.tmux.conf In konsole: $ echo $TERM xterm In tmux: $ echo $TERM screen-256color Still colors doesn't work in tmux: boris@vasilisa:~$ PROMPT_GREEN=`tput setf 2` boris@vasilisa:~$ PROMPT_RED=`tput setf 4` boris@vasilisa:~$ PROMPT_BLACK=`tput setf 8` boris@vasilisa:~$ PS1='\[$PROMPT_RED\]\w\[$PROMPT_GREEN\]:\[$PROMPT_BLACK\] ' Results in a black-and-white color prompt. Also no color with ls. screen I have force_color_prompt=yes in ~/.bashrc. Still: boris@vasilisa:~$ PROMPT_GREEN=`tput setf 2` boris@vasilisa:~$ PROMPT_RED=`tput setf 4` boris@vasilisa:~$ PROMPT_BLACK=`tput setf 8` boris@vasilisa:~$ PS1='\[$PROMPT_RED\]\w\[$PROMPT_GREEN\]:\[$PROMPT_BLACK\] ' Doesn't make prompt colorful. But in contrast to tmux -- ls lists files with color. So I guess tput setf just shouldn't work with terminal multiplexers? Edit I had to change setf to setaf, and also change the color codes: PROMPT_BLACK=`tput setaf 0` PROMPT_RED=`tput setaf 1` PROMPT_GREEN=`tput setaf 2` PS1='\[$PROMPT_RED\]\w\[$PROMPT_GREEN\]:\[$PROMPT_BLACK\] ' I don't need to aliase tmux, setting set-option -g default-terminal "screen-256color" in ~/.tmux.conf is suffice. So I put # colorful prompt PROMPT_BLACK=`tput setaf 0` PROMPT_RED=`tput setaf 1` PROMPT_GREEN=`tput setaf 2` PS1='\[$PROMPT_RED\]\w\[$PROMPT_GREEN\]:\[$PROMPT_BLACK\] ' # enable color support of ls and also add handy aliases if [ -x /usr/bin/dircolors ]; then test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" alias ls='ls --color=auto --group-directories-first' alias dir='dir --color=auto' alias vdir='vdir --color=auto' alias grep='grep --color=auto' alias fgrep='fgrep --color=auto' alias egrep='egrep --color=auto' fi # man pages with color! export LESS_TERMCAP_mb=$'\E[01;31m' export LESS_TERMCAP_md=$'\E[01;31m' export LESS_TERMCAP_me=$'\E[0m' export LESS_TERMCAP_se=$'\E[0m' export LESS_TERMCAP_so=$'\E[01;44;33m' export LESS_TERMCAP_ue=$'\E[0m' export LESS_TERMCAP_us=$'\E[01;32m' # enable colors: force_color_prompt=yes in both: ~/.bashrc and ~/.bash_login and then colors work in tmux.
Well as you quite correctly guessed setf is not correct capability for setting foreground color in context of xterm-256color(screen-256color) terminfo entry. You should use setaf (set foreground color using ANSI escape). $ echo $TERM screen-256color $ infocmp -1 | grep setf $ infocmp -1 | grep setaf setaf=\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m, Note: you should not need to do alias tmux='TERM=xterm-256color tmux', make sure your terminal emulator when started reports correct value of TERM=xterm-256color if (1) is true then tmux will correctly set your TERM to screen-256color inside it, also it will for example correctly set it if you are running on linux console to screen.linux, there might be case you need to manipulate it but generaly not
Getting 256 colors to work in terminal multiplexer
1,500,100,452,000
I made a script that runs fine manually, but can't get it to run with the description in How to start a script file on boot?. I have run update-rc.d -f minecraft.start defaults This is what my /etc/init.d/minecraft.start is like #!/bin/bash case "$1" in start) screen -S minecraft.start /home/phirephoenix/minecraft/bukkitserver/start_server.sh echo "Server started on screen minecraft" ;; stop) screen -X -S minecraft.start kill echo "Server shutting down" ;; *) echo "Usage: /etc/init.d/minecraft.start {start|stop}" exit 1 ;; esac exit 0 ~ As the script works, I won't be adding it, since it's the default. And this is my startup log /var/log/boot.log Begin: Loading essential drivers ... done. Begin: Running /scripts/init-premount ... done. Begin: Mounting root file system ... Begin: Running /scripts/local-top ... done. Begin: Running /scripts/local-premount ... done. Begin: Running /scripts/local-bottom ... done. done. Begin: Running /scripts/init-bottom ... done. fsck from util-linux 2.20.1 /dev/sda1: clean, 66452/4325376 files, 1205648/17301248 blocks * Starting configure network device [ OK ] * Starting Mount network filesystems [ OK ] * Starting Failsafe Boot Delay [ OK ] * Stopping Mount network filesystems [ OK ] * Starting Bridge socket events into upstart [ OK ] * Starting SMB/CIFS File Server [ OK ] * Starting configure network device [ OK ] * Stopping OpenSSH server [ OK ] * Starting OpenSSH server [ OK ] * Starting NetBIOS name server [ OK ] * Starting Mount network filesystems [ OK ] * Stopping Failsafe Boot Delay [ OK ] * Starting configure network device [ OK ] * Starting System V initialisation compatibility [ OK ] * Stopping Mount network filesystems [ OK ] * Starting SMB/CIFS File and Active Directory Server [ OK ] * Stopping cold plug devices [ OK ] * Stopping log initial device creation [ OK ] * Starting enable remaining boot-time encrypted block devices [ OK ] * Starting configure network device security [ OK ] * Starting configure virtual network devices [ OK ] * Stopping configure virtual network devices [ OK ] * Starting save udev log and update rules [ OK ] * Stopping save udev log and update rules [ OK ] Skipping profile in /etc/apparmor.d/disable: usr.sbin.rsyslogd * Starting AppArmor profiles [ OK ] * Stopping System V initialisation compatibility [ OK ] * Starting System V runlevel compatibility [ OK ] * Starting ACPI daemon [ OK ] * Starting save kernel messages [ OK ] * Starting automatic crash report generation [ OK ] * Starting regular background program processing daemon [ OK ] * Starting deferred execution scheduler [ OK ] * Stopping save kernel messages [ OK ] * Starting CPU interrupts balancing daemon [ OK ] * Starting crash report submission daemon [ OK ] * Starting domain name service... bind9 [ OK ] **<BIG BLANK AREA RIGHT HERE, DON'T GET IT>** **[screen is terminating]** **Server started on screen minecraft** apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName * Starting web server apache2 [ OK ] * Stopping System V runlevel compatibility [ OK ] It does execute the echo inside start, but it also says screen is terminating. What is causing this problem here? I run Ubuntu Server, it seems screen is installed and working. So new approach, using the upstart feature (or what I should call it). I kind of understood the runtimelevel things after some short googeling, and it should now start on one of the four runtimelevels i have set, or stop, on halt/reboot etc. made /etc/init/bukkit.conf much like the one warlock made. All the # are added for commenting here, and are not on the actual script. description "Bukktiserver" author "[email protected]" start on runlevel [2345] stop on runlevel [016] pre-start script echo " * Bukkitserver started" # I don't know if this does anything at all end script exec sudo /home/phirephoenix/minecraft/bukkitserver/start_server.sh # Had to sudo, or else it would get permission denied. Any ideas? Now I can start the server with typing sudo start bukkit, but it still does not run automaticly. bukkit is in my initctl list with bukkit stop/waiting (For everyone wondering bukkit is a minecraft server software.) So. I use a .conf to make it a upstart service, want the script to run without me having to do anything (automaticly before any logon). Is there a problem with the actuall jarfile to be run is in my homefolder? I can't really remember if my homefolder is encrypted or not, but it might be. Could this be a problem? Will I have to use symlinks or something (if symlinks are almost like shortcuts, but it ain't?) What am I missing here? Ps: I has also removed the screen startup thingy, with update-rc.d remove.
I didn't remember screen having a daemon mode, apparently it does. Change the screen line for the following: screen -dmS minecraft.start /home/phirephoenix/minecraft/bukkitserver/start_server.sh The new parameter -dmS "Start as daemon: Screen session in detached mode.", which is the combination of -d -m and the -S that you are already using.
Make screen start as Daemon for a Minecraft server
1,500,100,452,000
I got a brain smashing problem with Fedora 16 and my serial port. I use the serial to monitor an STB on which I'm developping. The STB runs on Linux and when booted, I launch the program I'm working on through the serial interface. Now, my program outputs lots of traces when I'm debugging, and I get loads of buffer overrun errors in dmesg. This makes debugging the application a mess, because the serial output gets unreadable. So, what's bothering me is that when I was running on Fedora 15, there was no buffer overrun at all! Some more details on my setup: Fedora Core 16 under Cinnamon / gnome-terminal for the serial. Uname: 3.2.6-3.fc16.x86_64 to connect the serial port, I use this command: screen -R -d -t "Serial" /dev/ttyS0 115200 Any idea of how I could fix that? (some more details:) $ cat /proc/tty/driver/serial serinfo:1.0 driver revision: 0: uart:16550A port:000003F8 irq:4 tx:3395 rx:11899157 fe:6 brk:4 oe:3496 RTS|DTR ### ^^^^^^^ ### overflow errors 1: uart:16550A port:0000EC98 irq:17 tx:32 rx:0 CTS|DSR|CD 2: uart:unknown port:000003E8 irq:4 3: uart:unknown port:000002E8 irq:3 Typical dmegs output: [370425.080452] ttyS0: 24 input overrun(s) [370426.092382] ttyS0: 30 input overrun(s) [370427.109291] ttyS0: 36 input overrun(s) [370428.173344] ttyS0: 28 input overrun(s) [370429.583198] ttyS0: 26 input overrun(s) [370430.638700] ttyS0: 32 input overrun(s) :( :( :( Output of sudo setserial -v -a -g /dev/ttyS0: /dev/ttyS0, Line 0, UART: 16550A, Port: 0x03f8, IRQ: 4 Baud_base: 115200, close_delay: 50, divisor: 0 closing_wait: 3000 Flags: spd_normal skip_test low_latency
According to the Fedora 16 documentation /etc/rc.serial is responsible for setting up the serial lines. Has anything changed here between your 15 and 16 install? Setting "low latency" and "rx/tx_trigger" (if possible) might help. I remember that the 16550A has a 15-byte-input-buffer. Somehow you can set at which fill-level an interrupt is being generated - I used 7 bytes for a tradeoff between reliability and speed (with DOS). Perhaps the rx/tx-trigger about does a comparable tuning. Update 2012-03-12: I just checked on my workstation (CentOS5 - should be comparable to Fedora): rpm -qd setserial shows the available documentation. There is a README and a sample rc.serial file - see the README. Apart from that - I looked again at your output: spd_normal does not look ok to me. You want 115 kb - so you propably should set spd_vhi (see man setserial). The reason for this is that you can not request more than 38.4 kb, since the UART-standard did not allow for more. Later on came 57.6kb then 115kb - there had to be a "trick" to set these speeds, too.
Buffer overrun on Fedora 16 serial
1,500,100,452,000
Using debian unstable with Gnome 3 but I think this has always happened. If I log out and then log back in again it seems the X session is restarted or in some way changed. In any case, when I start a terminal in the second session and re attach the screen, it's no longer possible to start X apps. (message is 'Cannot open display'). Is there an environment variable I can set or command I can run so that the screen session knows the new X details, or do I always have to start a new screen session?
I suppose that you have some problem with xauthorization. Please check if the value of XAUTHORITY environment variable changes each time you start a new X session. If it is true, you have to update this variable in each shell you have inside screen, because their environ contains still the value it has the time you started screen.
'Cannot open display' on restored GNU screen session
1,500,100,452,000
I am connecting to a serial port using screen: screen /dev/cu.usbserial-A703XAOG. The device on the other end sends only a carriage return to separate lines. Screen only starts at the beginning of the line when receiving a carriage return, and does not go down a line, and thus overwrites the last line of output with the next line of output. I can change the icrnl setting of the serial port, and it will convert the carriage return to a line feed. Although screen now goes down a line before writing the next line of output, it doesn't start at the beginning when receiving only a line feed. I dumped the .termcap file using the Ctrl-A, Ctrl+.. I read up on termcap and I learned that: If the terminal has a command that moves to the first column of the next line, that command can be given as nw (newline). source So this is my current ~/.screenrc file: termcap SC nw=^M Where SC matches the name in the dumped .termcap file. This does not give the effect that I hoped for. Maybe the termcap command is not the way to go? How can I make screen go down a line AND start at the beginning when receiving only CR from a serial device? Edit: Here is the output of sudo stty -f /dev/cu.usbserial-A703XAOG -a when screen is connected to the serial port: speed 9600 baud; 0 rows; 0 columns; lflags: -icanon -isig iexten -echo echoe echok echoke -echonl echoctl -echoprt -altwerase -noflsh -tostop -flusho -pendin -nokerninfo -extproc iflags: -istrip -icrnl -inlcr -igncr -ixon -ixoff -ixany -imaxbel -iutf8 -ignbrk brkint -inpck ignpar -parmrk oflags: -opost -onlcr -oxtabs -onocr -onlret cflags: cread cs8 -parenb -parodd -hupcl clocal -cstopb -crtscts -dsrflow -dtrflow -mdmbuf cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = ^@; eol2 = ^@; erase = ^?; intr = ^C; kill = ^H; lnext = ^V; min = 100; quit = ^\; reprint = ^R; start = ^Q; status = ^T; stop = ^S; susp = ^Z; time = 2; werase = ^W; Edit: I understand some software may solve this, for example, in PuTTY I would need to enable the "implicit LF in every CR" setting, and in Serial I would need to enable "Interpret Standalone CR as CRLF". But my question is specifically about screen, because that is the software I am using currently to connect to the serial port. Edit: Screen emulates the VT100 terminal, and it should recognize control sequences (source). I need to set "Automatic Linefeed Mode" (also known as new line mode). This should be done using the set mode control sequence with the parameter value 20: ESC [ 20 h. How can I pass this control sequence to screen?
Something that seemed to work for me was to manipulate the pseudo-tty that screen has by sending it the newline mode escape sequence you found, and also giving it an stty command to convert the carriage return to a newline. Use ps a to find the pty: 16947 pts/4 Ss+ 0:00 screen -S myscreen /dev/ttyS0 and then give the commands pty=/dev/pts/4 stty -F $pty ocrnl echo -en '\e[20h' >$pty
How can I make screen go down a line AND start at the beginning when receiving only CR from a serial device?
1,500,100,452,000
Which software provides /usr/bin/lock or /local/bin/lck ? The manual says that GNU Screen will call a screenlock program. But I don't have them in my system. Also my $LOCKPRG is empty. So is there any standard Linux software which I can install that provides lock facility for GNU Screen ?
My edition of screen on Debian (package version 4.1.0~20120320) has lock functionality built-in; hitting C-a x locks the entire environment (so that not even detach with C-a d is permitted). The Debian version of the man page for screen writes, "Call a screenlock program (/local/bin/lck or /usr/bin/lock or a builtin if no other is available)." If you want to lock a terminal session you can use vlock. From the man page, "vlock is a program to lock one or more sessions on the Linux console." I also tried installing vlock and running LOCKPRG=$(type -p vlock) screen. After hitting C-a x to lock the screen I saw that screen was correctly calling vlock to lock the screen. Again, the entire environment was locked so I couldn't suspend screen with C-a d.
What software is lock or lck
1,404,212,370,000
I am not quite sure if there is any subtle or wide differences between screen and xterm. I have used screen before and had it being described as kind of like a multiplexer and have tried xterm a few times. Can anyone explain the differences between the two as well as the pros and cons to them both?
you don't see actual terminals all that often anymore, but for instance the Linux text consoles on (CTRL +) ALT + F1 through F6 are considered terminals. xterm is a terminal emulator for systems running the x-window system and a graphical user interface. It provides only a single terminal, typically running a single process (an interactive shell by default). Konsole and similarly Gnome Terminal are slightly more advanced terminal emulators for the GUI. You run screen from within a terminal or a terminal emulator like xterm or PuTTY. In that single terminal window screen functions like a window manager to run multiple virtual terminals.
How are "xterm" and "screen" related?
1,404,212,370,000
Scenario; I have SSH'ed to a machine, opened a new screen session, and fired off a script. Some days later I SSH back to that machine, re-attach the screen session and look at the output that has been generated, however; I can't scroll back through the output. From what I can see, screen stores one "screens worth" of stdout output. If my script has generated 100 lines of output in 48 hours, I can't see it all, just the last 40 odd lines or so. Is there a way to make screen store all stdout from the script I leave running, so I can re-attach the screen and PgUp/PgDn through it as if it were a script running on my local machine? Perhaps screen isn't the most optimal way to do this? Is there a better method for leaving scripts running on remote machines after log out, and being able to re-attach to that process at a later date and view all the output?
Screen does keep a log of past output lines; it's called the “scrollback history buffer” in the Screen documentation. To navigate through the scrollback, press C-a ESC (copy). You can use the arrow and PgUp/PgDn keys to navigate, as well as other keys to search and copy text. Press ESC to exit scrollback/copy mode. By default, Screen only keeps 100 lines' worth. Put a defscrollback directive in your .screenrc to change this figure. If you want a complete log from your script, save it in a file. Run it inside Screen to be able to connect back to the parent shell and easily see if the script is still running, suspend and restart it, etc. Or fork it off with nohup. To monitor the log file while it's growing, use tail -f.
Leave remote command running storing output
1,404,212,370,000
I have a really old console application that I want to make a bit more resilient. The program is used this way: the user uses a custom terminal emulator to connect to a remote machine through ssh the user starts a shell script the shell script might start a long-running progress database process. Obviously, sometimes users simply lose the ssh connection to the machine, and in this case, the ssh session is terminated, the shell script running inside is terminated, and finally the progress database process is terminated as well. In like one case out of a thousand this causes corruption in the database, so I'd like to prevent it from happening. What I tried so far: starting a screen or tmux session before starting the shell script - this doesn't work because the application needs the TERM variable to be set to at386 (and it bypasses termcap/terminfo completely... ugh...) nohup/disown the progress process - this doesn't work because the shell script and the progress process are continuously communication with each other in obscure ways it seems Any other idea of how to make sure that the progress process doesn't terminate when the ssh session is killed?
Add term at386 to your .screenrc in order to override TERM. If this doesn't help, try dtach instead of Screen (which doesn't do any terminal emulation itself).
How to prevent a program from dying when its ssh session dies?
1,404,212,370,000
I'm not sure whether this is regarding a vim command or a screen command, although I think it's the latter. I use vim under screen all the time, and every once in a while will hit a key combo that freezes the virtual terminal I'm using. I can see everything, and I can still issue screen commands on that terminal, but I can't perform any actions within the terminal itself. I can create/flip to other virtual terminals and they all work nicely. I've no idea what I'm doing to lock up one particular terminal. Also, searching for answers online, CTRL-Q and CTRL-S are mentioned everywhere. Hitting CTRL-Q does nothing, and given the ambiguity of it, I tried both CTRL-q and CTRL-Q. --edit-- One other detail is that I'm using a Macbook, but I ~think~ I've had the same problem using KDE/Mint on a PC.
The accepted answer talks about flow control for the terminal you are running GNU Screen in. This would not result in the behaviour you are describing since you wouldn't be able to flip to and use your other Screen-terminals. The behavior you are describing sounds like you turned flow control on within GNU Screen itself. If you hit Ctrl+A followed by S this will send XOFF to the current Screen-terminal, but will leave the other Screen-terminals you could switch to alone. To get things working again, simply hit Ctrl+A followed by Q in the terminal that you want to get moving again.
How do I un-freeze my vim session under screen
1,404,212,370,000
My ubuntu VM does not run cron jobs with a TTY (not even when I log in and run the command from the user's env). Because of this, cron can't run tmux or screen, preventing programs (specifically rtorrent in this case) to be run in the background in a simple and attachable way. What is the best approach to running a program like rtorrent on boot while making it easy to attach, detach, and kill the process from any terminal? I assume just running the equivalent of rtorrent & should do it, but this is not as convenient as screen/tmux.
If you use the -d option with tmux new, it won't attach to or require a tty. From man tmux: new-session [-AdDEP] [-c start-directory] [-F format] [-n window-name] [-s session-name] [-t group-name] [-x width] [-y height] [shell-command] (alias: new) Create a new session with name session-name. The new session is attached to the current terminal unless -d is given. [...] For example: tmux new -d -s rtorrent rtorrent That creates a new tmux session called "rtorrent" and runs rtorrent inside it. You will probably need to configure ~/.tmux.conf, and run a script to start rtorrent (rather just the bare rtorrent command) in order to setup the run environment correctly. The user who owns the cron job can attach to the session at any time with: tmux attach -t rtorrent The equivalent for Screen is screen -d -m -S rtorrent rtorrent from the cron job and screen -S rtorrent -rd to attach later.
What is the best way to attach to a cron program without TTY
1,404,212,370,000
What's the best way to run a command inside a screen session such that its parent shell can be accessed? I want to be able to restart it from within the same screen session. The best I've managed to come up with is the following: $ cat mr-t.sh #!/bin/bash top exec /bin/bash and then: screen -e'^\\\' -S top-in-screen ./mr-t.sh Then, if top stops running, I'll at least get a new shell within the same screen session I can work with. This isn't very elegant, though, and I can't quite convince myself that the signal will reliably be sent to the right process if I hit C-c. Moreover, C-z doesn't work at all. I'm using bash 3.2.48 on OSX and 3.2.39 on Linux. Both are probably patched by OS vendors. There's nothing special about the top command here, of course. [As an aside, -e'^\\\' reassigns the Magick Screen Key from C-a (a bad default if there ever was one) to C-\.]
Since asking this question, I've adopted a different but much more effective solution: use tmux. Start a new named, detached session: $ tmux new -d -s top Send a command to its zeroth window. $ tmux send-keys -t top:0 "top" C-m C-m is equivalent to hitting return. Often it's what you want; sometimes you'll want to leave it out. tmux' command set is well-documented. So it's easy to write far more complicated scripts to drive it. Normally this would be an extremely obnoxious answer, but since it's my question I'll allow myself some leeway, especially since I never really got any of the other methods to work reliably. In contrast, I was able to script tmux correctly the first time I tried to.
How to run a command inside screen such that you can get back to the command's parent shell?
1,404,212,370,000
How can I disable the key combination Ctrl+C on GNU-screen? Actually I would have to get used to it, but I press Ctrl+C rather than Ctrl+A+D out of habit.
Now I've found the answer myself. The instructions defscrollback 30000 bindkey "^C" echo 'Blocked. Please use [Ctrl]+[A] + [Ctrl]+[Enter] + [Y]' bindkey "^D" echo 'Blocked. Please use [Ctrl]+[A] + [Ctrl]+[Enter] + [Y]' bind "^M" quit in the file ~/.screenrc lead to the fact that C-c only executes the echo command, thus no longer sends an interrupt. Instead you can stop the screen with ^M or Ctrl+Enter. Because I use bind (unlike bindkey) you have to press C-a first. The confirmation prompt can be confirmed with Y. The advantage of this solution is that I don't have to change the actual Java or Python program. Please remember that running screen sessions must be restarted in order to read the new ~/.screenrc file. (This path depends on the user, e.g. /root/.screenrc or /home/user/.screenrc.) Helpful links: Docu: http://web.mit.edu/gnu/doc/html/screen_13.html Find your own key combination: https://unix.stackexchange.com/a/116588/239596 Tested with Screen version 4.01.00devel (GNU) 2-May-06 Ubuntu 14.04.5 LTS MobaXterm v10.9 Build 3656 (Windows)
Disable Ctrl+C in GNU screen?
1,404,212,370,000
Whenever I create a new window in gnu screen I usually give it a name which persists between disconnects, but I notice that with oh-my-zsh distribution of zsh the title gets reset when I run a command in the window. Basically it gets reset to (x* ~) where x is the window number. Not only that when I run a command in remote session in that window the title which was set locally gets changed to the command run in the remote window if the remote shell is zsh. This doesn't happen with bash. e.g. lets say I create a new window in screen with the title as (2* ~) and then set the title to user@remotehost because I am going to connect to remotehost as user. When I run ssh user@remotehost to connect to remotehost the title reverts to (2* ~). When in remotehost I run htop the title changes to htop which I don't want. It seems as though zsh is propagating the remote windows command into the local window's title even if it is connected to another session. This seems to happen only under zsh as it never happens with bash. Is there some setting zsh or oh-my-zsh that overrides the previous behaviour? I haven't changed by .screenrc on switch to zsh and here it is. # got a fancy hardstatus line noted below hardstatus on hardstatus alwayslastline # hardstatus string "%w" # blagged this hardstatus like from https://bbs.archlinux.org/viewtopic.php?id=55618, not quite sure what it does # extended from http://unix.stackexchange.com/questions/195209 and , uptime command disabled # http://www.gnu.org/software/screen/manual/html_node/String-Escapes.html#String-Escapes hardstatus string '%{= kG}%{C}Screen:%{Rk}Host:%H %1`%{c}%{= kG}[%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{C} %d-%m %{W}%c %{g}]' backtick 1 30 30 sh -c 'screen -ls | grep --color=no -o "$PPID[^[:space:]]*" | cut -d '.' -f 2' # backtick 2 60 60 /usr/bin/uptime
It can be disabled in .zshrc by uncommenting the line: # Uncomment the following line to disable auto-setting terminal title. # DISABLE_AUTO_TITLE="true" It is applied in the functions omz_termsupport_precmd and omz_termsupport_preexec, which are in ~/.oh-my-zsh/lib/termsupport.zsh
How can I stop zsh (oh-my-zsh) from resetting screen window titles?
1,404,212,370,000
I started an fsck locally from tty1 on my Linux server and it seems to take forever. Would I have thought about this before or known I would have run a screen fsck. Is there any way to monitor tty1 via SSH or see the output from the fsck process running? I don't need to interact, just see how it's going.
If tty1 is the first virtual console on a Linux system, you can view its contents via /dev/vcs1: cat /dev/vcs1 (as root). (Thanks to Sato Katsura for pointing out that this is Linux-specific!)
Monitor/spy on tty1 or see the output from tty1 via SSH? [duplicate]
1,404,212,370,000
Is there a risk of losing files during compression if process dies? I'm gzipping big files using wildcard, but accidentally running it without screen or nohup. Is there a risk to lose source files if I cancel gzip compression during creating archive? Gzip version: gzip 1.3.5 (2002-09-30) Please let me know, I'm afraid of loosing data.
No there is no chance of losing during compression. Only when the file is complete processed is the source deleted (that is, if you don't specify -k or --keep, in which case the source is not deleted at all).
gzip - is there a risk to lose files during compression if process dead?
1,404,212,370,000
Is it possible to load multiple configuration files in Gnu screen? I tried multiple -c options, in vain. The basic idea is to keep my default ~/.screenrc loaded, and add a custom session configuration above it.
What I do is that I have a common screenrc file and I include it from custom session files. For example I have ~/.config/screen/gnus.screenrc containing sessionname gnus source common.screenrc chdir / screen -t gnus emacs -nw -f gnus And I run scr gnus to open this session, where scr is a script that arranges to either attach to a running session or open a new session with the specified name, and uses the session name to construct the path to the configuration file. #!/bin/sh session_name=$1 rc_file=~/.config/screen/$session_name.screenrc exec screen -c "$rc_file" -S "$session_name" -r -R -d "$@"
Gnu screen : load multiple configuration files
1,404,212,370,000
I have created a long running screen session with many windows and the C-a A command to rename a window is not working. What is the text command for renaming a window? I have tried :caption string windowname but it doesn't work. Is that the right command or am I missing something?
That is the title command, e.g,. :title bad-window In the manual: title [windowtitle] Set the name of the current window to windowtitle. If no name is specified, screen prompts for one. This command was known as aka in previous releases. If the shortcut is not working, of course, the long name may not work either.
What is the text command for naming a window in gnu-screen?