How do I send the same command to a subset of all windows in a screen session - gnu-screen

In the answer to this post Corey Henderson explains how you can use the at and stuff commands in screen to send commands to all windows of a screen session at once. I would like to know how I can stuff the input buffers to some windows at the same time. In other words, I would like to use a filter to specify which windows should receive the input and which should not.
It would be great if I could filter on the window number instead of the user name or the window name because bash likes to change the window name sometimes and it is inconvenient to modify the .bashrc on multiple machines. Also, sometimes I don't have control over which user I am running the command as.
So far I have only been able to run a command on either the currently active window or all windows at once.

The only way I have found to do windows filtering when using the atcommand is by using windows names.
By default screen's windows names are set after the actual command name of the program created in the window, for me this is usually bash. But windows names can be changed to whatever you prefer with Ctrl+A. If your windows' names change dynamically, check you don't have Dynamic Titles enabled.
So in practice that means you can give related windows a common prefix and then use at "prefix#" stuff "command" to execute the command only on those windows whose names matches the filter.
Imagine we have the following windows opened in our screen session:
0$ front1 - 1$ front2 - 2$ back1 - 3$ back2 - 4$ back3 - 5$ db1 - 6$ db2
The next command would send the service ntpd stop command to windows starting by the string back, that is back1, back2, back3:
at "back#" stuff "service ntpd stop^M"

Related

Set Windows Explorer window title

I work with multiple Explorer windows that use different user credentials and I was wondering if there is a way to set a static title for each window to be able to determine which one uses which user credentials, like window A title set to "user abc" - since the titles change to the currently opened directory which is rather confusing sometimes with multiple windows open
I'm looking for as simple solution as possible, batch, VBScript, etc., something that can be easily ran from either a command line or a script file that doesnt need any compilation, conversion or specific software installed, for example:
open explorer.exe title="custom title"
So far I wasn't able to find any scripts that could handle that - 3rd party applications are out of the question.
Not sure if it's even possible, tried to find anything for few days now to no avail.
According to here its possible to do it for iexplorer (internet explorer)
so by a blind guess it might be possible to do it the same way for explorer
windows>run>regedit.exe
HKEY_CURRENT_USER > Software > Microsoft > Windows > CurrentVersion > Explorer and a new data with string as value type and window title as value name
And by changing theme it is possible to achieve a same or maybe similar objective, everything explained here could be done with a batch script

Sending commands to a Tera Term via script file

I am testing some boards and the system used to test these is Tera Term. In Tera Term I use the Serial Port to send commands to the board in order to log in and run certain settings that I want.
Instead of typing these commands each time I test a board I want to create a program that sends these commands without the requirement to type them again and again each time.
Also I need to set a delay between each command as the system needs to to load between them.
Question
How can automate the typing of commands and delay between subsequent commands in teraterm?
I used the Tera Term Language (TTL) and created a macro which solved my problem. I used code to wait for a prompt from the system and then print out the command I wanted.
Here's a link to the TTL syntax:
http://ttssh2.osdn.jp/manual/en/macro/syntax/
Don't use Tera Term for that. It is not made for scripting, but rather for interactive use. Try to get a command line serial terminal emulator.
If you are on Linux you can use screen or there like.
If you are on Windows you can just write echo command > COM1 in a normal com.exe-window, according to this link: https://batchloaf.wordpress.com/2013/02/12/simple-trick-for-sending-characters-to-a-serial-port-in-windows/
(Replace COM1 with the name of your serial interface)
Make sure you don't have your Tera Term open while you use the echo-command, otherwise you'll get "Access Denied".

Process.Start does not always work

I created a protocol generation tool that reads some data from a websource, allows the user to filter some of the fields an generate a protocol based on given filterdata. The protocol is generated as a word document that is edited multiple times, on multiple layers, before shown to the user.
For some users the line:
Process.Start(pathtowordfile)
does not open Word, for others it works fine.
Even more strange: if the useres try to generate the protocol the first time it opens. if they change one of the filters and generate again, the file does not open. But it is generated correctly, you are able to open it manually.
We are using Windows 7 on all machines and, in general, the User has no administrativ privileges on the machine.
Are there any alternatives to
Process.Start()
?
Not sure how the code can sometimes work, but the critical bit I think would be to make sure you set UseShellExecute=true when you are trying to Process.Start a file that is not an executable.
https://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.useshellexecute%28v=vs.110%29.aspx
I haven't looked into it in quite awhile, but last I checked shell execute relies on the Word application to be properly registered with DDE so Windows knows what to do with a .doc(x) file. Word may not be installed "properly".
after trying varios things, including Wonko's hint, I dicided to use the interop.Word.Wordapplication to display the document. It doesn't explain why process.start not does the job but anyway, now everybody of the users is happy^^

Execute Macro-Script on Remote Computer

I have an requirement to execute macro-script kept on remote machine. DCOM Configuration setting is not set to allow communication between two computers. Even it's not possible to change the DCOM setting in my scenario.
Can I achieve the same requirement using Remote Desktop connection and then invoking macro script (through VBA code)?
I don't know exactly how to invoke script kept on remote machine using VBA?
Any idea/suggestions welcomed!!
This may not exactly answer your question, but may give you an idea.
I faced a the same problem with an application built in Access and the only way I could achieve this is by programming the macro I wanted to run into the application and then let the application periodically check a table on a share drive for "Go" command every few seconds.
On the share drive there was a table like this:
command_id | user | command
======================================
8 | "john.doe" | "update_me"
And all the applications were checking this table. If the app identified itself as user "john.doe", it decided to run the pre-programmed macro "update_me" and delete the row afterwards to prevent it from running again.
You can easily program more advanced stuff, like parameters, periodical execution etc.
It's not perfect, but it works quite nicely. Currently, I have the table on the SQL server and the command request takes cca 0.01s and I use it very often.

Switching screen sessions from inside an existing session

I've tried a bunch of commands but they all attach the session into the current session and they as you can imagine it bails when I try to reattach it later as it's already attached in the session nest.
I create sessions for each project I work on with windows to remote servers, logs and vim.
But everytime I want to switch I have to C-a d then screen -DR
I'd rather be able to just type a single command.
Thanks
AFAIK this is not possible with screen and I know of no way to easily work around this limitation. The issue here is that each screen session is independent and has no knowledge of other sessions.
If this is a feature you will use often, I would recommend switching to tmux which does this with <C-b>s. I've used both screen and tmux extensively and have not regretted favoring tmux this past year whenever a terminal multiplexer was called for.
On a side note running nested screen sessions is not too difficult, just send two escapes and commands go to the inner screen session, it helps if the escape is a single character, I like:
escape ``