linux后台执行命令screen的使用

    linux对于处理复杂和长时间进行人机交互的任务,建议使用使用screen命令,在后台执行。
    如何开始screen后台执行任务呢?很简单,执行screen,按回车键进出入子界面,在子界面内执行我们希望长时间执行的任务。
    对于系统未安装screen的通过yum install安装一下yum install screen
    下面来举例示范一下: 我们切换到oracle用户,然后执行RMAN备份任务,中途我们暂停screen子任务(ctrl+a 再按d键),显示[detached]表示我们已经返回父界面

点击(此处)折叠或打开

  1. [root@indsdb ~]# screen
  2. [root@indsdb ~]# su  - oracle
    [oracle@indsdb ~]$ rman target /
    Recovery Manager: Release 11.2.0.4.0 - Production on Tue Apr 19 10:38:04 2016
    Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
    connected to target database: INDSDB (DBID=1797260764)
    RMAN> backup database;
    Starting backup at 2016-04-19 10:38:30
    using target database control file instead of recovery catalog
    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: SID=670 device type=DISK
    channel ORA_DISK_1: starting full datafile backup set
    channel ORA_DISK_1: specifying datafile(s) in backup set
    input datafile file number=00006 name=/oracle/database/oradata/indsdb.ora
    input datafile file number=00010 name=/oracle/database/oradata/indsdb03.ora
    input datafile file number=00011 name=/oracle/database/oradata/indsdb04.ora
    input datafile file number=00008 name=/oracle/database/oradata/mtstest.ora
    input datafile file number=00001 name=/oracle/database/oradata/indsdb/system01.dbf
    input datafile file number=00002 name=/oracle/database/oradata/indsdb/sysaux01.dbf
    input datafile file number=00009 name=/oracle/database/oradata/indsdb02.ora
    input datafile file number=00003 name=/oracle/database/oradata/indsdb/undotbs01.dbf
    input datafile file number=00007 name=/oracle/database/oradata/indsdb/ids_interface.ora
    input datafile file number=00005 name=/oracle/database/oradata/indsdb/example01.dbf
    input datafile file number=00004 name=/oracle/database/oradata/indsdb/users01.dbf
    channel ORA_DISK_1: starting piece 1 at 2016-04-19 10:38:31








                             
    [detached]
    [root@indsdb ~]# 

    可以通过screen -ls 查看正在运行的screen任务,并通过screen -r pid 返回screen子界面,通过exit退出screen后台任务( [screen is terminating]

点击(此处)折叠或打开

  1. [root@localhost ~]# screen -ls
  2. There is a screen on:
  3. 3754.pts-0.localhost (Detached)
  4. 1 Socket in /var/run/screen/S-root.
  5. [root@localhost ~]# exit
    exit


    [screen is terminating]
    [root@localhost ~]# 

    screen常用的参数

点击(此处)折叠或打开

  1. [root@localhost ~]# screen -help
  2. Use: screen [-opts] [cmd [args]]
  3. or: screen -r [host.tty]
  4. Options:
  5. -4 Resolve hostnames only to IPv4 addresses.
  6. -6 Resolve hostnames only to IPv6 addresses.
  7. -a Force all capabilities into each window's termcap.
  8. -A -[r|R] Adapt all windows to the new display width & height.
  9. -c file Read configuration file instead of '.screenrc'.
  10. -d (-r) Detach the elsewhere running screen (and reattach here).
  11. -dmS name Start as daemon: Screen session in detached mode.
  12. -D (-r) Detach and logout remote (and reattach here).
  13. -D -RR Do whatever is needed to get a screen session.
  14. -e xy Change command characters.
  15. -f Flow control on, -fn = off, -fa = auto.
  16. -h lines Set the size of the scrollback history buffer.
  17. -i Interrupt output sooner when flow control is on.
  18. -l Login mode on (update /var/run/utmp), -ln = off.
  19. -ls [match] or
  20. -list Do nothing, just list our SockDir [on possible matches].
  21. -L Turn on output logging.
  22. -m ignore $STY variable, do create a new screen session.
  23. -O Choose optimal output rather than exact vt100 emulation.
  24. -p window Preselect the named window if it exists.
  25. -q Quiet startup. Exits with non-zero return code if unsuccessful.
  26. -Q Commands will send the response to the stdout of the querying process.
  27. -r [session] Reattach to a detached screen process.
  28. -R Reattach if possible, otherwise start a new session.
  29. -s shell Shell to execute rather than $SHELL.
  30. -S sockname Name this session .sockname instead of ...
  31. -t title Set title. (window's name).
  32. -T term Use term as $TERM for windows, rather than "screen".
  33. -U Tell screen to use UTF-8 encoding.
  34. -v Print "Screen version 4.01.00devel (GNU) 2-May-06".
  35. -wipe [match] Do nothing, just clean up SockDir [on possible matches].
  36. -x Attach to a not detached screen. (Multi display mode).
  37. -X Execute as a screen command in the specified session.
  38. [root@localhost ~]#



来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27039319/viewspace-2083900/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/27039319/viewspace-2083900/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值