I work on a terminal font and I'd like to take screenshots of various terminals (at least xterm, gnome-terminal and konsole) running a rendering test application. Executing the command is not a problem, but the usual, portable X way of doing it, the xwd command, doesn't seem to be very script-friendly and only works on X apps (xterm, in this case) and (unsurprisingly) ignores events from Wayland windows.
Figured it out (ish). All that's needed is to add a gnome-screenshot -w to the program I want to run. In my specific case, I added a script that ran the rendering test, then slept for two seconds (so that Konsole drops the window size widget) and then ran the screenshot command:
#!/bin/sh
./test_font_rendering.py
sleep 2 # Needed for Konsole to clear the window size
# Capture the active window to a file given as a parameter
gnome-screenshot -w -f $1.png
So, in order to generate the samples, you'd need something like:
gnome-terminal -- bash -c './test_font_rendering.sh gnome-terminal'
xterm -e './test_font_rendering.sh xterm'
Related
I'm trying to view all commands I have entered and their outputs. I understand that I can use 'history' to view all of my recent commands. However, is there a way I can check for previous outputs of those commands? I have tried looking it up and there does not seem to be a way.
It only stores history of the commands you ran (which you can retrieve by typing history). Unless you already have set the scroll-back to a very high number, there is no way to see the outputs that are older than the set value of scroll-back. Also setting this value to a very high number will make your scrolling sluggish since the lines are stored in the memory. Cloud Shell uses Tmux, which has a scroll back buffer of 2000 lines by default.
To store your future commands and their outputs, there are few options:
Using screen
Start a screen session by entering screen. Once you are inside ‘screen’, press Ctrl-a, then :, then enter log. All the I/O will be captured in screenlog files in the directory where you started the screen command.
Using script
You can start by typing script. A script session will start that will capture all the I/O to a file named typescript. You can exit the script session by Ctrl-d and view the logs in the typescript file.
Using tee
tee is a handy tool. You can do something like this:
$ tmux | tee log.txt
This will open a new bash shell inside the one you are already running. When you exit out of this, you can see the outputs in the file called log.txt
Other ways
As Dustin Kirkland suggested in this post, you can also use byobu. Although, I have never used terminal screencasting tools such as Shelr also sounds like an option.
Other ways
Cloud Shell commands to run and a link that explains more. This will exit the terminal and thus delete all the scroll back buffer, resetting it to empty, but in the future it will save 5000 lines rather than 2000.
$ tmux show-options -g | grep history
history-limit 2000
$ echo "set -g history-limit 5000" >> ~/.tmux.conf
$ exit
$ tmux show-options -g | grep history
history-limit 5000
If you type…
$ man tmux
… you can find the documentation for this setting (search by typing '/history-limit' + (enter)).
‘history-limit lines’ set the maximum number of lines held in window history. This setting applies only to new windows - existing window histories are not resized and retain the limit at the point they were created.
I'm lazy, and I prefer that computers do my work for me. I ssh into several machines on a daily basis, so I created a simple script that launches some xterm windows and places them in positions I want (as you can see, I'm using bash):
#!/bin/bash
xterm -geometry 80x27+1930+0 &
xterm -geometry 80x27+2753+0 &
xterm -geometry 80x27+1930+626 &
xterm -geometry 80x27+2753+626 &
However, the next thing I do is go to the first window and type in
ssh server_a
then in the second
ssh server_b
and so on. What I'd like to do is have my script do the ssh commands in each xterm window, and then leave the windows open for me to do my work. I've seen the -e option for xterm, but the window closes after I execute my command. Is there a way to do this?
I apologize if this is a duplicate question. I've searched around and haven't had any luck with this. Many thanks!
I'd love to see a more elegant answer, but what I came up with does work:
xterm -e bash -c 'echo foo; exec bash'
Replace echo foo with the command of your choice, and you're good to go.
This answer gives one of the best answers I've seen so far to do this. Use the bash --init-file flag either in the shebang or when executing the terminal:
#!/bin/bash --init-file
commands to run
... and execute it as:
xterm -e /path/to/script
# or
gnome-terminal -e /path/to/script
# or
the-terminal -e bash --init-file /path/to/script/with/no/shebang
My only real complaint with the exec option is if the command executed prior to exec bash is long running and the user interrupts it (^C), it doesn't run the shell. With the --init-file option the shell continues running.
Another option is cmdtool from the OpenWin project:
/usr/openwin/bin/cmdtool -I 'commands; here'
# or
/usr/openwin/bin/cmdtool -I 'commands; here' /bin/bash
... where cmdtool injects the commands passed with -I to the slave process as though it was typed by the user. This has the effect of leaving the executed commands in the shell history.
Another option is to use gnome terminator. This creates and positions terminals interactively, and you can set up each terminal to run commands within terminator preferences.
Also does lots of extra tricks using keybindings for things like move, rotate, maximise/minimise of terminals within the containing terminator window
See: https://superuser.com/a/610048
"ClusterSSH controls a number of xterm windows via a single graphical console window to allow commands to be interactively run on multiple servers over an ssh connection"
https://github.com/duncs/clusterssh/wiki
$ cssh server_a server_b
$ command
I have recently come across this post which says that it is possible to force a script to run in screen with a shebang. My question is, how does one do this if I want to reconnect to an existing screen session (and thus force the script to run under screen).
So, on my server, when I do screen -list, I see:
There is a screen on:
22566.myscreen (10/26/13 23:47:09) (Detached)
1 Socket in /var/run/screen/S-admin.
Now, I have the following bash script, and I would like the bash script to be run with the above screen session. At the moment, I have something like this:
#!/usr/bin/screen -r "myscreen" /bin/bash
# /home/foo/jobscripts/script.sh
#
echo $STY
git status
touch /home/foo/jobscripts/testsuccess.txt
exit 0
... but this obviously does not work and tells me Error: Unknown option r "myscreen" /bin/bash Wondering if there was a way to specify in shebang to reattach to my above screen.
For Linux, I think we should just use something like pid.sessionname.
For other Unix-like OS, it may also indicate the TTY like this pid.tty.sessionname.
To be sure, consult your manpage of screen : man screen
I need an example of gnome-terminal command to read lines of text from a file and executes them one by one in different terminal or a tab.
So this would be the process. I would run gnome terminal command and it would read 10 commands from a file. Then it would execute those 10 commands in 10 different tabs/terminals. And of course those tabs/terminals would remain opened. I found this question Avoid gnome-terminal close after script execution?
The third answer from the top is very helpful. I managed to open 1 command from a file. But I need 1 file with 10 command lines to be opened like I wrote above.
Thanks.
I recommend to use screen for this, if that can be acceptable to you.
You could create a commands.screenrc file like this:
screen bash -c 'command1; echo press any key; read'
screen bash -c 'command2; bash'
screen mutt
screen emacs
screen
You can define as many programs as you want. Start screen with:
screen -c commands.screenrc
I don't know what kind of commands you want to run. If you want to see their output, then write like the first example above: execute the command in a bash shell, which will "pause" after the command was executed. Or the second line, which, after running the command will start another bash shell. Otherwise the screen window would exit automatically.
If you are not familiar with screen, you will need to learn some basic key strokes to get around, and to be able to switch between windows. The first few pages of this presentation should be enough to get you started.
When using GNU screen, if you enter a screen session and then split it into desired layout.. is it possible to also have a full screen shell that you can switch to within the same session? Or once you start splitting does that mean you are constrained to one view and you can only alternate between visible split panes and then switch active shells within those panes?
I often split a screen session to monitor multiple logs or looped command output at the same time but I'd also like a full screen shell to work on as well without having to have a separate screen sessions that i need to detach from split/attach to full screen etc..
If screen can't do this, can tmux or similar do it? Any pointers?
many thanks
fLo
I tried to do this with screen. The best I could come up with was to have multiple sessions (with different escape characters). The multiple log windows were all in one session, and the other session contains, in one window, screen -r log. Then I could split the log session, and still be able to cycle through the other session windows.
I believe it is possible in tmux, but I have not made the switch (yet).
EDIT: It definitely is possible, and very easy, in tmux. And the switch was very easy (there's a screen-keys.conf file in tmux examples that I started with). This is a script I wrote to create a full screen session with 3 windows, the third has 3 panes in it, one 20% and the other two 40%. It's callable from crontab: #reboot
tmux new-session -d -s base /bin/bash
tmuxwin() {
tmux new-window -t base -n $1 /bin/bash
sleep 1
shift
tmux send "$1" C-m
}
tmuxwin second "echo second"
# These all end up in one window
tmuxwin thirddotone "echo 3.1"
tmuxwin thirddottwo "echo 3.2"
tmuxwin thirddotthree "echo 3.3"
# join 3.1 to 3.2. Give 3.1 20%
tmux select-window thirddotone
tmux joinp -p 80 -s +
# join 3.3 to 3.2. Even split
tmux joinp -s +
# and fix the names...
tmux rename-window three
# I am waiting for you, Vizzini. You told me to go back to the beginning.
# So I have. This is where I am, and this is where I’ll stay. I will not be moved.
tmux select-window -t 0
So my recommendation is to switch to tmux. I've been using tmux for less than a week and am not looking back.