New thing I learned in screen

6 views
Skip to first unread message

Jas Eckard

unread,
Jul 15, 2021, 4:58:18 PM7/15/21
to UCLUG
I was listening to a podcast today, and one of the things the guest
talked about was "back in the day" he created a website that was
basically a blog. In that blog, he would journal the things he
recently learned, including the mistakes he made along the way. That
got me reminiscing about "the old days" in this group. We used to do
that. Linux was new, and we didn't have a lot of resources to go to.
No Stack Exchange (Server Exchange), and no Google. I used to do it
with UCLUG, but I got "busy". Well, I'm going to try to do it again.
So, here's something I learned yesterday:

I had to ssh to a bunch of servers, and send basically the same
commands to all of them at the same time. Normally, I would use
`clusterssh` to do that (if I don't already have `SaltStack` or
`Ansible` setup), but I was already connected to all of them from the
jump server inside one `screen` session. Wouldn't it be great if,
like in `clusterssh`, you could send a command to all your `screen`
windows? Wait, maybe you can.

I eventually found the answer (yes, on Server Exchange, but it had a
link to a blog post). I looked in the man page, sure enough, it's
there, I just didn't know what to look for.

TL;DR:

While in the screen session (I re-attached, for example), type:

<CTRL-A>:at '#' stuff "command args^m"

To break it down:

- <CTRL-A> - Chord the <CTRL> key and the letter 'a' (this is the
"signal" to `screen` that the next command is for it).
- : - The colon character brings up a `screen` commandline (similar to
what `vi` does).
- at - The `at` command sends something to the specified screen "windows".
- '#' - There's some sort of complicated way of specifying which
"windows" you want, but I figure I'll always want to send to all of
them, and that's what singlequote-pound-singlequote does.
- stuff - The `stuff` command is a thing that does a thing, it says
what in the manual, but I TD;DR'd, I just know I always need the word
"stuff" (I assume it's the verb form of "stuff").
- "command args^m" - This is the command and args that I want to send
to every "window". This seems to follow shell quote interpretation,
so single- vs double-quotes are important. And quoting is not
necessary if I don't need to send arguments to a command, for example,
or I'm just answering "yes" to a prompt. If I want to send special
characters, use the caret-form. In this example caret-M (`^M` or
`^m`, I discovered it's case-insensitive) sends a carriage return
(<CR> or '\r'). I use `man ascii` for reference for caret-form.

--Jas
.
..:

Robert Meier

unread,
Sep 7, 2021, 3:06:41 PM9/7/21
to 'Darrell Lee' via Upstate Carolina Linux Users Group
What is the topic for September 14?

I should have responded earlier.

I learned recently how to execute python one-liners (aka snippets, sniglets).

> python -c "import math: print(matb.atan(1))"
# 0.78539816

> echo '{"8": "eight", "b": "bee"》
   python -c "import json;import pprint;pprint.pprint(json.loads(input()))"
# format json string submitted to stdin

> # feed to command-line shell
python # interpret python
-c # everything remaining  on line is command
import json # load a module
; # command separated
import print # load another module 
pprint.pprint # pretty print
json.loads # parse json
Input() # stdin stream

Hopefully Helpful,

Bobby


--
You received this message because you are subscribed to the Google Groups "Upstate Carolina Linux Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to uclug+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/uclug/CAC%2BRRjtrGfp_KfSX%3DE0pneTW-ZwdhEwBdOkc8UOH_%2BzoywwLHw%40mail.gmail.com.li
Reply all
Reply to author
Forward
0 new messages