Home » Questions » Computers [ Ask a new question ]

Running commands on Putty without fear of losing connection

Running commands on Putty without fear of losing connection

"How do you use the ""screen"" command effectively?
Is it:"

Asked by: Guest | Views: 258
Total answers/comments: 4
Guest [Entry]

"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."
Guest [Entry]

"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"
Guest [Entry]

"You'd be looking for

screen -x"
Guest [Entry]

"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."