13
12
How do you use the "screen" command effectively?
Is it:
Type "screen"
Type in command
Lose connection
Check back on lost session
How do I carry out step 4?
13
12
How do you use the "screen" command effectively?
Is it:
Type "screen"
Type in command
Lose connection
Check back on lost session
How do I carry out step 4?
18
With screen:
screencommandscreen -RD to reattach to the screen (if there's more than one you'll get a list of current screen sessions and you'll have to supply the session number) from a new sessionA simpler method that is useful for commands that leave logfiles or just throw some relevant output and do not need interactivity is nohup:
nohup command > logfile & tail -f logfile from a new session4
Screen is really powerful, and allows you to do exactly what you asked.
To see all your sessions, type
screen -list
Once you've identified a screen session to reconnect too, try
screen -dr SCREENID
which will nicely detach and re-attach your session.
You can also do a less nice,
screen -D -R
which will detach and logout remotely, if nesscessary, then reattach, or if that session doesn't exist, it will create it and notify the user. You can add a "-t NAME" to give shells or programs a title.
Within screen, use
command-c
to create a new window (So you don't need 4000000 screen sessions to disconnect and reconnect from), and change between them with
command-int
Indexing from 0, of course:P
Since you seem a bit unfamiliar with screen, I'm going to assume you could use some other info. I like the following commands, like:
-e xy
Which causes x to be the command character and y to be the character to generate a literal command character. The defaults are Ctrl-a and `a.
There's some more for you here: Screen! It's what's for programmers
2
screen -dr to detach and resume the previous screen session.
2
Here's what I have picked up about using screen (which I, too, have just started doing):
screen -S <name> creates a screen named '<name>'. This is quite useful if you want to have several screen sessions going at the same time. For instance, I have one I use normally and one I use for my persistent processes.screen -ls lists the running screens.screen -r <name> resumes a detached screen. If the screen is already attached somewhere, use screen -dr <name>.Also, when you start using screen, whenever you plan to leave, press ^a d (= ctrl-a followed by a d) to detach the screen you're currently running. It can then be resumed later.
In addition, I can recommend taking a look at ^a ? for a list of the different commands you can use while inside of a screen.
The most important of these (to me) are:
^a c to create a new window in your screen session.^a ^a to switch between the two last used windows.^a " to list the current windows in your session.^a Esc to scroll in your screen buffer.^a k to kill the current window.^a x to lock your screen session, in case you need to leave your computer and don't want people to mess with it.1
A quick Google search found this screen guide
http://www.rackaid.com/resources/linux-tutorials/general-tutorials/using-screen/
So from step b) you can detach the screen using :
"Ctrl - A" "d"
and then later after the connection has been lost and your connected once again find the screen using :
# screen -ls
and then reattach using :
# screen -r <screen_session_name>
1
you can also set up your environment to log you in and start screen right off the bat. There are many ways to do it. I chose to add this to my .bashrc file.
# screen management
if [ $SSH_TTY ] && [ ! $WINDOW ]; then
SCREENLIST=`screen -ls | grep 'Attached'`
if [ $? -eq "0" ]; then
echo -e "Screen is already running and attached:\n ${SCREENLIST}"
else
screen -U -R
fi
fi
0
You'd be looking for
screen -x
0
Step 4 is "screen -r"
If you got disconnected really forcefully, you might need to do "screen -r -d", to force it to disconnect from your old ssh session, which it thinks is still open.
0
For windows system
Open putty
then login in server
If you want to see screen in Console then you have to write command
Screen -ls
if you have to access the screen then you have to use below command
screen -x screen id
Note: step 3 is entirely optional. If you close your PuTTY session without detaching, you can still reattach with
screen -RD. – Duncan Jones – 2017-08-25T08:10:28.533