首页 > 技术 > screen命令

screen命令

2006年6月18日

大量拷贝时自然遇到的问题:
如果是ssh到主机上,开始批量的scp命令,如果这个ssh线程断线了,scp进程就死了

jufeng前几天给出的命令是nohup yourcmd &,可以保证ssh掉线了运行的命令也不会死,期间程序的输出会存在nohup.out文件中。
不过它的问题是如果程序中途会要求你输入东西就不行了,比如scp会要求输入远程主机的密码。就算用小于号重定向都不行。

今天查到一个命令screen,不错。
它起的作用像个软终端,或者叫软tty?可以在里面输命令,程序可以在里面运行,也有显示,按^a再^d可以这个screen中切出来,ssh断了自然也会….不过screen里面的东西还是在运行中的
如果想再进这个screen,可以打screen -ls,会显示一个现在正在运行的screen列表,形同:7518.pts-0.ftp  (Attached),然后再打screen -r 7518就能进入这个screen了

Screen is a full-screen window manager that multiplexes a physical ter-
       minal between several processes (typically interactive  shells).   Each
       virtual terminal provides the functions of a DEC VT100 terminal and, in
       addition, several control functions from the ISO 6429  (ECMA  48,  ANSI
       X3.64)  and ISO 2022 standards (e.g. insert/delete line and support for
       multiple character sets).  There is a  scrollback  history  buffer  for
       each virtual terminal and a copy-and-paste mechanism that allows moving
       text regions between windows.

       When screen is called, it creates a single window with a  shell  in  it
       (or  the  specified  command) and then gets out of your way so that you
       can use the program as you normally would.  Then, at any time, you  can
       create new (full-screen) windows with other programs in them (including
       more shells), kill existing windows, view a list of windows, turn  out-
       put  logging  on and off, copy-and-paste text between windows, view the
       scrollback history, switch between windows in whatever manner you wish,
       etc.  All  windows  run  their  programs completely independent of each
       other. Programs continue to run when their window is currently not vis-
       ible and even when the whole screen session is detached from the user’s
       terminal.  When a program terminates, screen (per  default)  kills  the
       window  that  contained  it.  If this window was in the foreground, the
       display switches to the previous  window;  if  none  are  left,  screen
       exits.

       Everything  you type is sent to the program running in the current win-
       dow.  The only exception to this is the one keystroke that is  used  to
       initiate  a  command  to  the window manager.  By default, each command
       begins with a control-a (abbreviated C-a from now on), and is  followed
       by one other keystroke.  The command character and all the key bindings
       can be fully customized to be anything you like, though they are always
       two characters in length.

       Screen does not understand the prefix “C-” to mean control.  Please use
       the caret notation (“^A” instead of “C-a”) as  arguments  to  e.g.  the
       escape  command  or  the -e option.  Screen will also print out control
       characters in caret notation.

       The standard way to create a new window is to type “C-a c”.  This  cre-
       ates  a  new window running a shell and switches to that window immedi-
       ately, regardless of the state of the process running  in  the  current
       window.   Similarly,  you can create a new window with a custom command
       in it by first binding the command to a keystroke  (in  your  .screenrc
       file  or  at  the “C-a :” command line) and then using it just like the
       “C-a c” command.  In addition, new windows can be created by running  a
       command like:

              screen emacs prog.c

       from  a shell prompt within a previously created window.  This will not
       run another copy of screen, but will instead supply  the  command  name
       and its arguments to the window manager (specified in the $STY environ-
       ment variable) who will use it to create the  new  window.   The  above
       example would start the emacs editor (editing prog.c) and switch to its
       window.

       If “/etc/utmp” is writable by screen, an  appropriate  record  will  be
       written  to  this  file for each window, and removed when the window is
       terminated.  This is useful for working with “talk”,  “script”,  “shut-
       down”,  “rsend”,  “sccs”  and  other similar programs that use the utmp
       file to determine who you are. As long as screen is active on your ter-
       minal,  the  terminal’s  own  record is removed from the utmp file. See
       also “C-a L”.

技术

  1. 目前还没有任何评论.
  1. 目前还没有任何 trackbacks 和 pingbacks.