I use linux screen heavily , generally if the OS didn't restart or say as long as the SCREEN process is there, I can re-attach to my terminals.
But I don't want to set-up the screens each time after my computer restarts that's tedious work.
so I generally setup a series of screens to run different categories of command
1. create a window, rename the screen, run specific command
2. etc...
Is there a way to create these screen setups automatically , say can I script to do that ?
Edit: what is more important here is how to paste some command into the window after the window is created.
Yes, of course.
You just need to specify the configuration of screen in ~/.screenrc.
If you want to use several configurations, you can create several config files
and start screens with -c key.
screen -c ~/.screenrc1
screen -c ~/.screenrc2
screen -c ~/.screenrc3
Example of ~/.screenrc:
screen -t news 8 newsbeuter
screen -t jabber 9 freetalk
here will be open two windows: on 8 -- newsbeuter (the name of the window news); on 9 — freetalk (the name of the window jabber).
Related
This question already has an answer here:
Read screen character from terminal
(1 answer)
Closed 2 years ago.
Is it possible to get a snapshot of the text contents of a Linux terminal?
Both tput and terminfo support "cup" mode (e.g. tput smcup to start alternate buffer mode) which implies they must save the screen state somewhere. Is it possible to get these contents?
You can save a snapshot of the text contents of a Linux terminal to
a file using GNU Screen
hardcopy
feature but only if you started screen beforehand. Apart from that,
you can restore terminal contents saved with tput smcup using
tput rmcup but this works only in xterm (not only in xterm
terminal emulator itself but also in other terminal emulators
providing that $TERM is set to xterm. It doesn't work in Linux TTY
though).
Four Methods to Take Screenshot Capture in Ubuntu Linux
Use Print Screen
This is the most common method to take screenshots. Pressing the “Print Screen” button will take the screenshot of the “Entire Visible Screen”.
When we want to take a particular window, we can use “Alt+Print Screen”. Alt+PrintScreen will take only the particular window which is currently active.
Use gnome-screenshot
gnome-screenshot utility is part of the GNOME Desktop Environment, which can also be used to take screenshot. It also has a command line mode (gnome-screenshot)
From the command-line, just type the command “gnome-screenshot” to do the same. The command will take a screenshot and provide a dialog to save it.
$ gnome-screenshot
Capture Only the Current Window:
From the UI, to take the screenshot of the current active window alone, select “Grab the Current Window” and click “Take Screenshot”.
From the command-line, use the -w option as follows to do the same.
$ gnome-screenshot -w
Take Screenshot After Some Delay:
From the UI, you can also set a delay before taking the screenshots. Set the “Grab after a delay” to the required number of seconds. This will be really helpful when we need to take screen shots of navigation.
From the command-line, use -d option to do the same. -d 2 is used for delaying the screenshot for 2 seconds. So within the 2 seconds, we can make the window which we want to take screenshot as active.
$ gnome-screenshot -w -d 2
Capture a Particular Area:
From the UI, if you want to take a particular rectangle area alone, then select “Grab a Particular area” and click “Take Screenshot”.
From the command-line, use the -a option to do the same. Once this command is entered, the mouse pointer will be changed, and you can drag and select which area to take screenshot.
$ gnome-screenshot -a
Take Screenshot Including or Excluding Window Border:
From the UI, you can also include or exclude the window border by selecting/deselecting “Include the Window Border” option.
Use ImageMagic’s Import Command
ImageMagick is an open source software suite for displaying, converting, and editing raster image files. It comes with various command line tools, and one of that is “import”. Now we will see, how we can use import to take screenshots. You can install it by using apt-get on debian/ubuntu as follows:
apt-get install imagemagick
Capture Entire Screen using -window root option
Use the “-window root” option to take screenshot of the complete screen. The screenshot will be saved in the file name provided in the command line.
$ import -window root Pictures/Image5.png
ImageMagick supports more that 100 file types. You can use any one of them to store the output.
Use GIMP
You can also take screenshot from gimp. Launch gimp, and click “File->Create->Screenshot”. A new dialog window will open with options similar to gnome-screenshot.
I have a Raspberry PI 3 running Fedora 21 with MATE. It is to be used to simply autoload firefox to a specific website and display some useful statistics from that page.
The tricky part is I have two different sections of that page that I need to see. I was able to get firefox to auto-start two different profiles and with the help of Greasemonkey it goes to the correct section of the pages needed. I now nee to be able to open both windows in fullscreen on two different workspaces at startup. Then I need the workspaces to autoswap like every 30 seconds. This will be on a TV overhead with the only access being SSh which is why it needs to be automated. This is beyond my knowledge now.
I have tried to use Compiz Rotate Cubes and Desktop Cubes, but I cant automate this. At this point I am at a loss.
EDIT: I have managed through a custom script to get Firefox in two profiles on two workspaces!!!! Still trying to get the desktop to switch.
I have actually solved this by writing two scripts
The first script switches workspaces 30 seconds after boot and opens the second Mozilla browser with a second profile.
Basically
#! /bin/bash
sleep 30 &&
wmctrl -s 1
firefox -P Profile2 -no-remote
sleep 15
wmctrl -s 0
The second script is an infinite while do:
while:;
do
sleep 30
wmctrl -s 1
sleep 30
wmctrl -s 0
done
I'm sure there are better ways to accomplish this, but this seems to work for us.
I'm using this very simple .screenrc:
logtstamp on
logfile /tmp/screenlog-%S.log
I tried launching screens with these two methods:
screen -L -S testing
screen -S tester -L
but the filename used is /tmp/screenlog.0S.log. What am I doing wrong? Using Screen version 4.00.03jw4 (FAU) 2-May-06, and according to the manual I should be able to name the log file using the session name
If you look at the man page (man screen) for your (8-year-old?) version of screen, you'll see it's missing the %S specifier. They must have added it since your version. I'm not sure why Ubuntu 12.04 shipped screen from 2006..
P.S. I'd advocate looking into tmux. It's a little bit harder to learn, but a lot more flexible: You can move windows between sessions, You can see multiple windows at once, You can nest sessions inside of other sessions, etc.
Also, if you are just looking to log the output of long-running processes, take a look at nohup.
I use some minor scripts at work under cygwin, and I would like to make them available to workmates with a familiar Windows icon. For instance, suppose I have the following:
cat *tsv | sort > combined_n_sorted.txt
Is there a simple way to make a corresponding icon, assuming cygwin is installed in my workmates' systems? These scripts may involve (cygwin's) python.
Thanks!
It seems that your question has two parts:
How to make scripts accessible on users' desktops.
How to give the each script a particular icon.
For (1), you could create a shortcut on the users' desktops that runs the following command:
C:\cygwin\bin\bash.exe -c 'cat *tsv | sort > combined_n_sorted.txt'
or if the commands are stored in a script,
C:\cygwin\bin\bash.exe -c /path/to/script
If you want to hide the console window from appearing while the script runs, you could use the run command (in the run package), e.g.:
C:\cygwin\bin\run.exe /bin/bash -c 'cat *tsv | sort > combined_n_sorted.txt'
# or
C:\cygwin\bin\run.exe /path/to/script
But it might be better for users to see the console window, so they know the script is running.
For (2), you can change each shortcut's icon individually by right-clicking on it and choosing Properties, but AFAIK that's a one-host-at-a-time change. I don't know of any batch way to do it, although no doubt there's a registry key you can set. Or, if you change the icon of the shortcut on your host and then distribute that shortcut, it might keep the same icon on other users' desktops, if the icon is a standard one that exists on their hosts.
I am using Putty to connect to a remote server. What I want to know is if there is any way to write my commands and allow them to keep running after I close the session with Putty. The reason for this is that I do not want to keep the computer ON all the time. Is there any way to do this?.
Update with the solution
For my question as it is presented the best solution is use one of the commands provided such as nohup, because you do not have to install any additional software. But if you are in the same problem use screen, install it and use it. It is amazing.
I have selected the answer of Norman Ramsey as favourite because propose several solutions using commands and screen. But please check the other answers specially the one of PEZ, then you get an insight of what screen is able todo.
screen! It's the best thing since sliced bread. (Yeah, I know others have already suggested it, but it's so good the whole world should join in and suggest it too.)
screen is like, like, ummmm ... like using VNC or the like to connect to a GUI destop, but for command shell windows. You can have several shell "windows" open at once in the same screen session. You can do stuff like:
Start a screens session using "screen -dR" (get used to using -dR)
run some commands in one window
press CTRL-A,C to create a new window open a file there in vim
press CTRL-A,0 to go back to the first window and issue some command on the file you just edited
CTRL-A, 1 to go back to your vim session
CTRL-A, C for yet another window and maybe do "sudo - su" (because you just happen to need a full root shell)
CTRL-A, 0 and start a background process
CTRL-A, C to create yet a new window, "tail -f" the log for that background process
CTRL-A, d to disconnect your screen then CTRL-D to disconnect from the server
Go on vacation for three weeks
Log on to the server again and issue "screen -dR" to connect to your existing screen session
check the log in the the fourth window with CTRL-A, 3 (it's like you've been there watching it all the time)
CTRL-A, 1 to pick up that vim session again
I guess you're starting to get the picture now? =)
It's like magic. I've been using screen for longer than I can remember and I'm still totally amazed with how bloody great it is.
EDIT: Just want to mention there's now also tmux. Very much like screen, but has some unique features, splitting the windows being the most prominent one.
nohup, disown, and screen are all good but screen is the best because unlike the other two, screen allows you to disconnect from the remote server, keep everything running, and then reconnect later to see what is happening. With nohup and disown you can't resume interacting.
Try using GNU Screen. It allows you to have several shells open at once. And you can disconnect from those running shells (i.e. close session with Putty) and they will keep doing their thing.
What you are looking for is nohup.
See the wiki link for how to use it.
screen is the best.
Try:
screen -dmS "MyTail" tail -f /var/log/syslog
This start command in background.
Use screen -r to list, and or screen -r Mytail to enter session.
If more users need access same session, use: screen -rx MyTail, and both or more users share the session.
If you can't use screen (because, for instance, your SSH session is being programmatically driven), you can also use daemonize to run the program as a daemon.
One way that works well for me is at.
at works like cron, but for a one-time job. I used it today to download a large file without having to keep my session alive.
for example:
$ at 23:55
at> wget http://file.to.download.com/bigfile.iso
at> ^D
You pass at a time (in the future) and it gives you a prompt. You enter the commands you want to run at that time and hit ctrl+d. You can exit out of your session and it will run the commands at the specified time.
Wikipedia has more info on at.
./command & disown
ssh localhost && ./command && exit